package cc.rengu.igas.momp.core.service.trans;

import cc.rengu.igas.momp.common.constant.CommonConstant;
import cc.rengu.igas.momp.common.dao.*;
import cc.rengu.igas.momp.common.dao.impl.*;
import cc.rengu.igas.momp.common.entity.*;
import cc.rengu.igas.momp.common.enums.*;
import cc.rengu.igas.momp.common.util.CommonMessageCheck;
import cc.rengu.igas.momp.common.util.JsonOperation;
import cc.rengu.igas.momp.common.util.MompAmountUtil;
import cc.rengu.igas.momp.facade.bean.*;
import cc.rengu.igas.momp.facade.request.EditMoneyOffMcDetailRequest;
import cc.rengu.igas.momp.facade.response.EditMoneyOffMcDetailResponse;
import cc.rengu.oltp.service.base.RadpService;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.enums.ChannelEnum;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.utility.bean.PageInfo;
import cc.rengu.oltp.utility.bean.PageResult;
import cc.rengu.oltp.utility.util.*;
import cc.rengu.utility.base.StringUtil;
import cc.rengu.utility.dbs.Database;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 减免类活动信息编辑功能实现
 *
 * @author Jinan Liu
 * @since 2020/4/1 10:59
 */
public class EditMoneyOffMcDetailInfoService extends RadpService {

    private String globalInstId;
    private String globalMcNo;
    private String globalTimeStamp;
    private String globalOprId;
    private String globalTxnDate;
    private final static String TABLE_NAME = TableNameEnum.T_M_MC_MO_INFO.getTableNameCode();
    private String globalSponsor;
    private String globalOrgId;
    private String globalMchntFlag;
    private BigDecimal zero = BigDecimal.ZERO;
    private String globalMcType;
    private boolean merFileFlag = false;
    private String globalFlowNo;
    private String flowAuditStatus = "";
    private String flowTmpAuditStatus = "";
    private String traceNo = "";
    private boolean auditStatusChangeFlag = false;

    @Override
    protected int bizInit(String s) {
        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizProcess(String s, int i) {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        try {

            EditMoneyOffMcDetailRequest editMoneyOffMcDetailRequest = new EditMoneyOffMcDetailRequest();
            ConvertUtil.convertOutput(editMoneyOffMcDetailRequest);

            EditMoneyOffMcDetailResponse editMoneyOffMcDetailResponse = new EditMoneyOffMcDetailResponse();
            editMoneyOffMcDetailResponse.setHeader(editMoneyOffMcDetailRequest.getHeader());
            BizResponse<EditMoneyOffMcDetailResponse> bizResponse = new BizResponse<>();
            bizResponse.setResult(editMoneyOffMcDetailResponse);

            /* 判断查询类型 */
            rglog.debug("TXN_NUM=<{}>", editMoneyOffMcDetailRequest.getHeader().getTxnNum());

            globalInstId = editMoneyOffMcDetailRequest.getHeader().getInstId();
            globalTimeStamp = new SimpleDateFormat(CommonConstant.TIMESTAMP_FORMAT).format(new Date());
            globalOprId = editMoneyOffMcDetailRequest.getQueryId();
            globalTxnDate = editMoneyOffMcDetailRequest.getHeader().getTransDate();
            globalOrgId = editMoneyOffMcDetailRequest.getQueryOrgId();
            if (null == editMoneyOffMcDetailRequest.getMchntInfoList() || editMoneyOffMcDetailRequest.getMchntInfoList().isEmpty()) {
                globalMchntFlag = CommonConstant.ZERO_COMMON_CONSTANT;
            } else {
                globalMchntFlag = CommonConstant.ONE_COMMON_CONSTANT;
            }
            globalMcType = editMoneyOffMcDetailRequest.getMcInfoObj().getMcType();

            String queryType = editMoneyOffMcDetailRequest.getQueryType();
            String queryRole = editMoneyOffMcDetailRequest.getQueryRole();
            String oprType = editMoneyOffMcDetailRequest.getOprType();

            rglog.debug("QUERY_TYPE=<{}>", queryType);
            rglog.debug("QUERY_ID=<{}>", globalOprId);
            rglog.debug("QUERY_ROLE=<{}>", queryRole);
            rglog.debug("OPR_TYPE=<{}>", oprType);

            /* 报文检查 */
            CommonMessageCheck.checkBizMessageHeader(queryType, globalOprId, queryRole, rglog);
            CommonMessageCheck.checkSingleValue(oprType, rglog);

            if (!StringUtil.isNullorEmpty(editMoneyOffMcDetailRequest.getMcInfoObj().getMcNo())) {
                globalMcNo = editMoneyOffMcDetailRequest.getMcInfoObj().getMcNo();
            }
            //判断是否上传商户文件
            if (!StringUtil.isNullorEmpty(editMoneyOffMcDetailRequest.getMrctFilePath())) {
                merFileFlag = true;
                rglog.info("减免类营销活动编辑，商户文件路径：" + editMoneyOffMcDetailRequest.getMrctFilePath());
            }

            //判断上送的商户信息和机构信息是否匹配，即参加活动的商户所属的机构有权限参加活动
            checkMchntAndOrgInfo(editMoneyOffMcDetailRequest);

            // 服务调用
            BizResponse<EditMoneyOffMcDetailResponse> bizResponseNew = editMoneyOffMcDetailInfo(
                    editMoneyOffMcDetailRequest, editMoneyOffMcDetailResponse, xmlTreeUtil);

            ConvertUtil.convertInput(bizResponseNew.getResult());

        } catch (BizException e) {
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, e.getCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, e.getMessage());
                xmlTreeUtil.setXmlTreeStringValue(CommonConstant.KEY_RESPDESC, e.getMessage());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e1));
            }
        } catch (Exception e) {
            rglog.error(StringUtil.ExceptionToString(e));
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
                xmlTreeUtil.setXmlTreeStringValue(CommonConstant.KEY_RESPDESC, e.getMessage());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e1));
            }
        }

        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizTerminate(String s) {
        return CommonConstant.PROCESS_SUCCESS;
    }

    /**
     * 减免类营销活动编辑方法
     *
     * @param editMoneyOffMcDetailRequest  减免类营销活动信息编辑接口请求对象
     * @param editMoneyOffMcDetailResponse 减免类营销活动信息编辑接口应答对象
     * @param xmlTreeUtil                  内部XML树
     * @return cc.rengu.oltp.service.model.BizResponse<cc.rengu.igas.momp.facade.response.EditMoneyOffMcDetailResponse> 减免类营销活动信息编辑接口应答对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:15
     */
    private BizResponse<EditMoneyOffMcDetailResponse> editMoneyOffMcDetailInfo(EditMoneyOffMcDetailRequest editMoneyOffMcDetailRequest, EditMoneyOffMcDetailResponse editMoneyOffMcDetailResponse, XmlTreeUtil xmlTreeUtil) throws Exception {

        BizResponse<EditMoneyOffMcDetailResponse> bizResponse = new BizResponse<>();

        /* 判断查询类型 */
        String queryType = editMoneyOffMcDetailRequest.getQueryType();
        String queryRole = editMoneyOffMcDetailRequest.getQueryRole();
        String oprType = editMoneyOffMcDetailRequest.getOprType();
        globalMcNo = editMoneyOffMcDetailRequest.getMcInfoObj().getMcNo();


        /* 判断用户的角色和权限 */
        if (QueryTypeEnum.BANK_QUERY_TYPE.getQueryTypeCode().equals(queryType)) {

            if (QueryRoleEnum.BANK_BASIC_QUERY_ROLE.getQueryRoleCode().equals(queryRole)) {
                /* 银行人员录入岗-正式表和临时表所有数据 */
                rglog.info("银行人员录入岗开始操作");
                if (OprTypeEnum.EDIT_SAVE.getOprTypeCode().equals(oprType)) {

                    rglog.info("保存数据流程开始");

                    /* 保存数据是完全新增数据的流程，需要生成营销活动编号 */
                    if (StringUtil.isNullorEmpty(globalMcNo)) {
                        /* 如果营销活动编号不存在，说明是全新的营销活动，需要生成一个营销活动编号，并新增全部数据； */
                        globalMcNo = generateNewMcNo(editMoneyOffMcDetailRequest.getMcInfoObj());

                        if (!StringUtil.isNullorEmpty(globalMcNo)) {
                            rglog.info("MC_NO=<{}>", globalMcNo);
                        }

                        /* 开启数据库事务 */
                        String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
                        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
                        if (null != corporation && !corporation.isEmpty()) {
                            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
                            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
                        }
                        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
                        dbsUtil.dbsBeginTransaction();
                        /* 全部新增流程，插入数据 */
                        insertAllMcInfoByBank(dbsUtil, editMoneyOffMcDetailRequest);

                        /* 正常结束数据库事务 */
                        dbsUtil.dbsEndTransaction(true);

                    } else {

                        /* 如果营销活动编号存在，需要根据当前数据库各状态判断是否可以更新数据 */
                        saveAllMcInfoByBank(xmlTreeUtil, editMoneyOffMcDetailRequest);
                    }

                    rglog.info("保存数据流程结束");

                } else if (OprTypeEnum.EDIT_SUBMIT.getOprTypeCode().equals(oprType)) {

                    rglog.info("提交审批流程开始");

                    /* 提交审批 */
                    submitMcInfo(editMoneyOffMcDetailRequest);

                    rglog.info("提交审批流程结束");

                } else if (OprTypeEnum.EDIT_DRAFT.getOprTypeCode().equals(oprType)) {

                    rglog.info("修改草稿流程开始");

                    /* 开启数据库事务 */
                    String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
                    String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
                    if (null != corporation && !corporation.isEmpty()) {
                        String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
                        dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
                    }
                    DbsUtil dbsUtil = new DbsUtil(dbPoolName);
                    dbsUtil.dbsBeginTransaction();

                    /* 修改草稿 */
                    updateAllDraftMcInfoByBank(dbsUtil, editMoneyOffMcDetailRequest);

                    /* 正常结束数据库事务 */
                    dbsUtil.dbsEndTransaction(true);

                    rglog.info("修改草稿流程结束");

                } else {
                    rglog.error("当前<{}>角色的查询用户<{}>无权限查看数据!", queryRole, queryType);
                    throw new BizException(RespCodeEnum.NOT_SUPPORTED_OPR_TYPE_ERROR.getRespCode(), RespCodeEnum.NOT_SUPPORTED_OPR_TYPE_ERROR.getRespDesc());
                }

            } else {
                /* 银行审批岗或银行发布岗 */
                rglog.error("当前<{}>角色的查询用户<{}>无权限查看数据!", queryRole, queryType);
                throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespDesc());
            }


        } else {
            /* 商户、代理商、收银员或用户 */
            rglog.error("当前<{}>角色的查询用户<{}>无权限查看数据!", queryRole, queryType);
            throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespDesc());
        }

        bizResponse.setRspSysId(ChannelEnum.MOMP.getChannelType());
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());

        editMoneyOffMcDetailResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        editMoneyOffMcDetailResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());

        editMoneyOffMcDetailResponse.setMcNo(globalMcNo);

        bizResponse.setResult(editMoneyOffMcDetailResponse);

        return bizResponse;
    }

    /**
     * 营销活动信息数据库实体类和接口实体类数据转换
     *
     * @param moneyOffMcInfoBean 减免类活动基本信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcMoneyOffInfo 减免类营销活动信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 15:18
     */
    private TMMcMoneyOffInfo convertMcInfo(MoneyOffMcInfoBean moneyOffMcInfoBean) throws Exception {

        // 检查上传字段 不能为负数
        checkMcInfoObjFieldHasNegativeNumber(moneyOffMcInfoBean);

        TMMcMoneyOffInfo tmMcMoneyOffInfo = new TMMcMoneyOffInfo();

        /* 法人机构号 */
        tmMcMoneyOffInfo.setInstId(globalInstId);
        /* 营销活动编号 */
        tmMcMoneyOffInfo.setMcNo(globalMcNo);
        /* 营销活动名称 */
        if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getMcName())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMoneyOffInfo.setMcName(moneyOffMcInfoBean.getMcName());
        }
        /* 营销活动类型 */
        if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getMcType())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMoneyOffInfo.setMcType(moneyOffMcInfoBean.getMcType());
        }
        /* 营销活动状态 */
        if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getMcStatus())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMoneyOffInfo.setMcStatus(moneyOffMcInfoBean.getMcStatus());
        }
        /* 活动起始日期 */
        if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getMcStartDate())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMoneyOffInfo.setMcStartDate(moneyOffMcInfoBean.getMcStartDate());
        }
        /* 活动截止日期 */
        if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getMcEndDate())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMoneyOffInfo.setMcEndDate(moneyOffMcInfoBean.getMcEndDate());
        }
        /* 活动结束日期 */
        if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getMcActualEndDate())) {
            /* 不需要计算，直接使用活动结束日期*/
            tmMcMoneyOffInfo.setMcActualEndDate(moneyOffMcInfoBean.getMcEndDate());
        } else {
            /* 不需要计算，直接使用接口上送内容 */
            tmMcMoneyOffInfo.setMcActualEndDate(moneyOffMcInfoBean.getMcActualEndDate());
        }
        /* 活动时间标志 */
        if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getMcTimeFlag())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMoneyOffInfo.setMcTimeFlag(moneyOffMcInfoBean.getMcTimeFlag());
        }
        /* 出资方 */
        if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getSponsor())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMoneyOffInfo.setSponsor(moneyOffMcInfoBean.getSponsor());
            globalSponsor = moneyOffMcInfoBean.getSponsor();
        }
        /* 参与次数限制 */
        if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getRestriction())) {
            tmMcMoneyOffInfo.setRestriction(CommonConstant.ZERO_COMMON_CONSTANT);
        } else {
            tmMcMoneyOffInfo.setRestriction(moneyOffMcInfoBean.getRestriction());
        }
        /* 客户范围 */
        if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getClientRange())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMoneyOffInfo.setClientRange(moneyOffMcInfoBean.getClientRange());
        }
        /* 商户范围 */
        if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getMerchantRange())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMoneyOffInfo.setMerchantRange(moneyOffMcInfoBean.getMerchantRange());

            if (!CommonConstant.SPECIFIC_MCHNT_LIST.equals(moneyOffMcInfoBean.getMerchantRange())) {

                /* 商户上月日均存款达标或商户上月日均交易额达标,以下三项必填 */

                /* 新增商户活动标志 */
                if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getNewMchntFlag())) {
                    throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
                } else {
                    tmMcMoneyOffInfo.setNewMchntFlag(moneyOffMcInfoBean.getNewMchntFlag());
                }
                /* 限制金额下限 */
                if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getAmtLimitFloor())) {
                    throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
                } else {
                    tmMcMoneyOffInfo.setAmtLimitFloor(MompAmountUtil.getTwoDecimal(moneyOffMcInfoBean.getAmtLimitFloor()));
                }
                /* 限制金额上限 */
                if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getAmtLimitCelling())) {
                    throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
                } else {
                    tmMcMoneyOffInfo.setAmtLimitCelling(MompAmountUtil.getTwoDecimal(moneyOffMcInfoBean.getAmtLimitCelling()));
                }
            } else {
                /* 指定商户列表,以下三项可不填 */

                /* 新增商户活动标志 */
                if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getNewMchntFlag())) {
                    tmMcMoneyOffInfo.setNewMchntFlag(moneyOffMcInfoBean.getNewMchntFlag());
                }
                /* 限制金额下限 */
                if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getAmtLimitFloor())) {
                    tmMcMoneyOffInfo.setAmtLimitFloor(MompAmountUtil.getTwoDecimal(moneyOffMcInfoBean.getAmtLimitFloor()));
                }
                /* 限制金额上限 */
                if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getAmtLimitCelling())) {
                    tmMcMoneyOffInfo.setAmtLimitCelling(MompAmountUtil.getTwoDecimal(moneyOffMcInfoBean.getAmtLimitCelling()));
                }
            }
        }
        /* 预算充值方式 */
        if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getBudgetRechargeMethod())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMoneyOffInfo.setBudgetRechargeMethod(moneyOffMcInfoBean.getBudgetRechargeMethod());
        }
        /* 预算 */
        if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getBudget())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMoneyOffInfo.setBudget(MompAmountUtil.getTwoDecimal(moneyOffMcInfoBean.getBudget()));
        }
//        /* 银行出资预算 */
//        if(StringUtil.isNullorEmpty(moneyOffMcInfoBean.getBankBudget())) {
//            tmMcMoneyOffInfo.setBankBudget(CommonConstant.ZERO_AMOUNT);
//        } else {
//            tmMcMoneyOffInfo.setBankBudget(MompAmountUtil.getTwoDecimal(moneyOffMcInfoBean.getBankBudget()));
//        }
        /* 预期参与商户数量 */
        if (StringUtil.isNullorEmpty(moneyOffMcInfoBean.getExpectMchntQty())) {
            tmMcMoneyOffInfo.setExpectMchntQty(CommonConstant.ZERO_COMMON_CONSTANT);
        } else {
            tmMcMoneyOffInfo.setExpectMchntQty(moneyOffMcInfoBean.getExpectMchntQty());
        }
        /* 银行出资比例 银行出资预算*/
        if (CommonConstant.SPONSOR_BANK.equals(moneyOffMcInfoBean.getSponsor())) {
            tmMcMoneyOffInfo.setBankBudgetRatio("1");
            tmMcMoneyOffInfo.setBankBudget(moneyOffMcInfoBean.getBudget());
        } else if (CommonConstant.SPONSOR_MCHNT.equals(moneyOffMcInfoBean.getSponsor()) || CommonConstant.SPONSOR_MCHNT_NORECHARGE.equals(moneyOffMcInfoBean.getSponsor())) {
            tmMcMoneyOffInfo.setBankBudgetRatio(CommonConstant.ZERO_COMMON_CONSTANT);
            tmMcMoneyOffInfo.setBankBudget(CommonConstant.ZERO_AMOUNT);
        } else {
            BigDecimal budget = new BigDecimal(moneyOffMcInfoBean.getBudget()).setScale(CommonConstant.DECIMAL_SCALE_TWO, RoundingMode.HALF_UP);
            BigDecimal bankBudget = new BigDecimal(moneyOffMcInfoBean.getBankBudget()).setScale(CommonConstant.DECIMAL_SCALE_TWO, RoundingMode.HALF_UP);
            BigDecimal bankBudgetRatio = bankBudget.divide(budget, CommonConstant.DECIMAL_SCALE_FIVE, RoundingMode.HALF_UP);
            tmMcMoneyOffInfo.setBankBudgetRatio(bankBudgetRatio.toString());
            tmMcMoneyOffInfo.setBankBudget(MompAmountUtil.getTwoDecimal(moneyOffMcInfoBean.getBankBudget()));
        }
        /* 审批状态-待提交审批状态 */
        tmMcMoneyOffInfo.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
        /* 创建人 */
        tmMcMoneyOffInfo.setOprId(globalOprId);
        /* 创建时间 */
        tmMcMoneyOffInfo.setCreateTime(globalTimeStamp);
        /* 最后修改人 */
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getLastOprId())) {
            tmMcMoneyOffInfo.setLastOprId(moneyOffMcInfoBean.getLastOprId());
        }
        /* 修改时间 */
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getUpdateTime())) {
            tmMcMoneyOffInfo.setUpdateTime(moneyOffMcInfoBean.getUpdateTime());
        } else {
            tmMcMoneyOffInfo.setUpdateTime(globalTimeStamp);
        }
        /* 审批拒绝原因 */
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getAuditRefuseReason())) {
            tmMcMoneyOffInfo.setAuditRefuseReason(moneyOffMcInfoBean.getAuditRefuseReason());
        }
        /* 发布拒绝原因 */
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getPublishRefuseReason())) {
            tmMcMoneyOffInfo.setPublishRefuseReason(moneyOffMcInfoBean.getPublishRefuseReason());
        }
        /* 备用字段1 */
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getRemark1())) {
            tmMcMoneyOffInfo.setRemark1(moneyOffMcInfoBean.getRemark1());
        }
        /* 备用字段2 */
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getRemark2())) {
            tmMcMoneyOffInfo.setRemark2(moneyOffMcInfoBean.getRemark2());
        }
        /* 备用字段3 */
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getRemark3())) {
            tmMcMoneyOffInfo.setRemark3(moneyOffMcInfoBean.getRemark3());
        }
        /* 备用字段4 */
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getRemark4())) {
            tmMcMoneyOffInfo.setRemark4(moneyOffMcInfoBean.getRemark4());
        }
        /* 备用字段5 */
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getRemark5())) {
            tmMcMoneyOffInfo.setRemark5(moneyOffMcInfoBean.getRemark5());
        }
        /* 创建机构 */
        if (!StringUtil.isNullorEmpty(globalOrgId)) {
            tmMcMoneyOffInfo.setCrtOrgId(globalOrgId);
        }
        if (globalMchntFlag.equals(CommonConstant.ONE_COMMON_CONSTANT)) {
            /* 活动发布批量任务状态 */
            tmMcMoneyOffInfo.setPublishBatchStatus(CommonConstant.PUBLISH_BATCH_SUCCESS);
        } else {
            /* 活动发布批量任务状态 */
            tmMcMoneyOffInfo.setPublishBatchStatus(CommonConstant.PUBLISH_BATCH_INITIAL);
        }
        /* 营销活动级别 0-非商户非银行级 1 商户级 2 银行级*/
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getMcLvlCd())) {
            tmMcMoneyOffInfo.setMcLvlCd(moneyOffMcInfoBean.getMcLvlCd());
        } else {
            tmMcMoneyOffInfo.setMcLvlCd(CommonConstant.ZERO_COMMON_CONSTANT);
        }
        /* 停车场业务标志 0-非停车场业务 1停车场业务*/
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getPrkBusnFlg())) {
            tmMcMoneyOffInfo.setPrkBusnFlg(moneyOffMcInfoBean.getPrkBusnFlg());
        } else {
            tmMcMoneyOffInfo.setPrkBusnFlg(CommonConstant.ZERO_COMMON_CONSTANT);
        }
        /* 普卡优惠次数*/
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getOdcrdDisTimes())) {
            tmMcMoneyOffInfo.setOdcrdDisTimes(moneyOffMcInfoBean.getOdcrdDisTimes());
        }
        return tmMcMoneyOffInfo;
    }

    /**
     * 营销活动机构信息数据库实体类和接口实体类数据转换
     *
     * @param mcOrgInfoBean 营销活动机构信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcOrgInfo 营销活动机构信息表
     * @author Jinan Liu
     * @since 2020/4/1 21:11
     */
    private TMMcOrgInfo convertMcOrgInfo(McOrgInfoBean mcOrgInfoBean) {
        TMMcOrgInfo mcOrgInfo = new TMMcOrgInfo();
        try {
            /* 法人机构号 */
            mcOrgInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcOrgInfo.setMcNo(globalMcNo);
            /* 机构编号 */
            mcOrgInfo.setOrgId(mcOrgInfoBean.getOrgId());
            /* 机构层级 */
            mcOrgInfo.setOrgHierarchy(mcOrgInfoBean.getOrgHierarchy());
            /* 机构名称 */
            mcOrgInfo.setOrgName(mcOrgInfoBean.getOrgName());
            /* 创建人 */
            mcOrgInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcOrgInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动机构信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcOrgInfo;
    }

    /**
     * 营销活动商户信息数据库实体类和接口实体类数据转换
     *
     * @param mcMchntInfoBean 营销活动商户信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcMchntInfo 营销活动商户信息表
     * @author Jinan Liu
     * @since 2020/4/1 21:10
     */
    private TMMcMchntInfo convertMcMchntInfo(McMchntInfoBean mcMchntInfoBean) {
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        try {
            /* 法人机构号 */
            mcMchntInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcMchntInfo.setMcNo(globalMcNo);
            /* 商户范围类型 */
            mcMchntInfo.setMchntType(mcMchntInfoBean.getMchntType());
            /* 商户范围号 */
            mcMchntInfo.setMchntNo(mcMchntInfoBean.getMchntNo());
            /* 商户范围名称 */
            mcMchntInfo.setMchntName(mcMchntInfoBean.getMchntName());
            /* 操作类型 */
            mcMchntInfo.setOprType(mcMchntInfoBean.getOprType());

            if (CommonConstant.SPONSOR_MIXED.equals(globalSponsor)) {
                /* 联合营销活动初始数据 */

                /* 新增商户标志 */
                mcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_OLD_FLAG);
                /* 退出标志 */
                mcMchntInfo.setExitFlag(CommonConstant.MC_EXIT_FLAG);
            } else {
                /* 银行全资或商户全资初始数据 */

                /* 新增商户标志 */
                mcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_OLD_FLAG);
                /* 退出标志 */
                mcMchntInfo.setExitFlag(CommonConstant.MC_NOT_EXIT_FLAG);
            }

            /* 达标日期 */
            mcMchntInfo.setQualifiedDate(globalTxnDate);
            /* 创建人 */
            mcMchntInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcMchntInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcMchntInfo;
    }

    /**
     * 营销活动用户规则信息数据库实体类和接口实体类数据转换
     *
     * @param mcUserInfoBean 营销活动用户信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcUserInfo 营销活动用户信息表
     * @author Jinan Liu
     * @since 2020/4/1 21:09
     */
    private TMMcUserInfo convertMcUserInfo(McUserInfoBean mcUserInfoBean) {
        TMMcUserInfo mcUserInfo = new TMMcUserInfo();
        try {
            /* 法人机构号 */
            mcUserInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcUserInfo.setMcNo(globalMcNo);
            /* 账户类型 */
            mcUserInfo.setAcctType(mcUserInfoBean.getAcctType());
            /* 账户 */
            mcUserInfo.setAcctNo(mcUserInfoBean.getAcctNo());
            /* 账户标志 */
            mcUserInfo.setAcctFlag(CommonConstant.ACCT_FLAG_NORMAL);
            /* 会员ID */
            mcUserInfo.setMemberId(mcUserInfoBean.getMemberId());
            /* 创建人 */
            mcUserInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcUserInfo.setCreateTime(globalTimeStamp);
            /* 卡bin类型处理数据 */
            if (mcUserInfoBean.getAcctType().equals("2") || mcUserInfoBean.getAcctType().equals("3")) {
                //每日限制优惠次数
                if (StringUtil.isNullorEmpty(mcUserInfoBean.getDayRestriction())) {
                    mcUserInfo.setDayRestriction(CommonConstant.ZERO_COMMON_CONSTANT);
                } else {
                    mcUserInfo.setDayRestriction(mcUserInfoBean.getDayRestriction());
                }
                //每周限制优惠次数
                if (StringUtil.isNullorEmpty(mcUserInfoBean.getWeekRestriction())) {
                    mcUserInfo.setWeekRestriction(CommonConstant.ZERO_COMMON_CONSTANT);
                } else {
                    mcUserInfo.setWeekRestriction(mcUserInfoBean.getWeekRestriction());
                }
                //每月限制优惠次数
                if (StringUtil.isNullorEmpty(mcUserInfoBean.getMonthRestriction())) {
                    mcUserInfo.setMonthRestriction(CommonConstant.ZERO_COMMON_CONSTANT);
                } else {
                    mcUserInfo.setMonthRestriction(mcUserInfoBean.getMonthRestriction());
                }
                //每季度限制优惠次数
                if (StringUtil.isNullorEmpty(mcUserInfoBean.getQuerterRestriction())) {
                    mcUserInfo.setQuerterRestriction(CommonConstant.ZERO_COMMON_CONSTANT);
                } else {
                    mcUserInfo.setQuerterRestriction(mcUserInfoBean.getQuerterRestriction());
                }
                //每年限制优惠次数
                if (StringUtil.isNullorEmpty(mcUserInfoBean.getYearRestriction())) {
                    mcUserInfo.setYearRestriction(CommonConstant.ZERO_COMMON_CONSTANT);
                } else {
                    mcUserInfo.setYearRestriction(mcUserInfoBean.getYearRestriction());
                }
                //活动期间优惠次数限制
                if (StringUtil.isNullorEmpty(mcUserInfoBean.getRestriction())) {
                    mcUserInfo.setRestriction(CommonConstant.ZERO_COMMON_CONSTANT);
                } else {
                    mcUserInfo.setRestriction(mcUserInfoBean.getRestriction());
                }
            }


        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcUserInfo;
    }

    /**
     * 营销活动时间规则信息数据库实体类和接口实体类数据转换
     *
     * @param mcTimeInfoBean 营销活动事件对象
     * @return cc.rengu.igas.momp.common.entity.TMMcTimeInfo 营销活动时间信息表
     * @author Jinan Liu
     * @since 2020/4/1 21:09
     */
    private TMMcTimeInfo convertMcTimeInfo(McTimeInfoBean mcTimeInfoBean) {
        TMMcTimeInfo mcTimeInfo = new TMMcTimeInfo();
        try {
            /* 法人机构号 */
            mcTimeInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcTimeInfo.setMcNo(globalMcNo);
            /* 顺序号 */
            mcTimeInfo.setRuleIndex(mcTimeInfoBean.getRuleIndex());
            /* 星期一日期标志 */
            if (StringUtil.isNullorEmpty(mcTimeInfoBean.getFlagMonday())) {
                mcTimeInfo.setFlagMonday(CommonConstant.WEEK_FLAG_NOT_SET);
            } else {
                mcTimeInfo.setFlagMonday(mcTimeInfoBean.getFlagMonday());
            }
            /* 星期二日期标志 */
            if (StringUtil.isNullorEmpty(mcTimeInfoBean.getFlagTuesday())) {
                mcTimeInfo.setFlagTuesday(CommonConstant.WEEK_FLAG_NOT_SET);
            } else {
                mcTimeInfo.setFlagTuesday(mcTimeInfoBean.getFlagTuesday());
            }
            /* 星期三日期标志 */
            if (StringUtil.isNullorEmpty(mcTimeInfoBean.getFlagWednesday())) {
                mcTimeInfo.setFlagWednesday(CommonConstant.WEEK_FLAG_NOT_SET);
            } else {
                mcTimeInfo.setFlagWednesday(mcTimeInfoBean.getFlagWednesday());
            }
            /* 星期四日期标志 */
            if (StringUtil.isNullorEmpty(mcTimeInfoBean.getFlagThursday())) {
                mcTimeInfo.setFlagThursday(CommonConstant.WEEK_FLAG_NOT_SET);
            } else {
                mcTimeInfo.setFlagThursday(mcTimeInfoBean.getFlagThursday());
            }
            /* 星期五日期标志 */
            if (StringUtil.isNullorEmpty(mcTimeInfoBean.getFlagFriday())) {
                mcTimeInfo.setFlagFriday(CommonConstant.WEEK_FLAG_NOT_SET);
            } else {
                mcTimeInfo.setFlagFriday(mcTimeInfoBean.getFlagFriday());
            }
            /* 星期六日期标志 */
            if (StringUtil.isNullorEmpty(mcTimeInfoBean.getFlagSaturday())) {
                mcTimeInfo.setFlagSaturday(CommonConstant.WEEK_FLAG_NOT_SET);
            } else {
                mcTimeInfo.setFlagSaturday(mcTimeInfoBean.getFlagSaturday());
            }
            /* 星期日日期标志 */
            if (StringUtil.isNullorEmpty(mcTimeInfoBean.getFlagSunday())) {
                mcTimeInfo.setFlagSunday(CommonConstant.WEEK_FLAG_NOT_SET);
            } else {
                mcTimeInfo.setFlagSunday(mcTimeInfoBean.getFlagSunday());
            }
            /* 起始时间 */
            mcTimeInfo.setStartTime(mcTimeInfoBean.getStartTime().trim());
            /* 结束时间 */
            mcTimeInfo.setEndTime(mcTimeInfoBean.getEndTime().trim());
            /* 创建人 */
            mcTimeInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcTimeInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcTimeInfo;
    }

    /**
     * 营销活动规则信息数据库实体类和接口实体类数据转换
     *
     * @param moneyOffRuleInfoBean 减免类营销活动规则信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcMoneyOffRuleInfo 减免类营销活动规则表
     * @author Jinan Liu
     * @since 2020/4/1 21:07
     */
    private TMMcMoneyOffRuleInfo convertMcRuleInfo(MoneyOffRuleInfoBean moneyOffRuleInfoBean) {

        TMMcMoneyOffRuleInfo moneyOffRuleInfo = new TMMcMoneyOffRuleInfo();

        // 检查上传字段 不能为负数
        checkRuleInfoFieldHasNegativeNumber(moneyOffRuleInfoBean);

        try {
            /* 法人机构号 */
            moneyOffRuleInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            moneyOffRuleInfo.setMcNo(globalMcNo);
            /* 顺序号  */
            moneyOffRuleInfo.setRuleIndex(moneyOffRuleInfoBean.getRuleIndex());
            /* 活动门槛 */
            moneyOffRuleInfo.setCriteria(MompAmountUtil.getTwoDecimal(moneyOffRuleInfoBean.getCriteria()));
            /* 优惠力度下限 */
            moneyOffRuleInfo.setDiscountFloor(MompAmountUtil.getTwoDecimal(moneyOffRuleInfoBean.getDiscountFloor()));
            /* 优惠力度上限 */
            moneyOffRuleInfo.setDiscountCelling(MompAmountUtil.getTwoDecimal(moneyOffRuleInfoBean.getDiscountCelling()));
            /* 总优惠数量 */
            moneyOffRuleInfo.setDiscountQuantity(moneyOffRuleInfoBean.getDiscountQuantity());
            /* 单次优惠限制 */
            moneyOffRuleInfo.setDiscountLimit(MompAmountUtil.getTwoDecimal(moneyOffRuleInfoBean.getDiscountLimit()));
            /* 优惠总预算 */
            moneyOffRuleInfo.setBudget(MompAmountUtil.getTwoDecimal(moneyOffRuleInfoBean.getBudget()));
            //活动为定额立减
            if (globalMcType.equals(McTypeEnum.REDUCTION_FIXED_AMOUNT.getMcTypeCode())) {
                /* 单日消耗预算 */
                moneyOffRuleInfo.setBudgetDayLimit(MompAmountUtil.getZeroDecimal(moneyOffRuleInfoBean.getBudgetDayLimit()));
            } else {
                /* 单日消耗预算 */
                moneyOffRuleInfo.setBudgetDayLimit(MompAmountUtil.getTwoDecimal(moneyOffRuleInfoBean.getBudgetDayLimit()));
            }
            /* 创建人 */
            moneyOffRuleInfo.setOprId(globalOprId);
            /* 创建时间 */
            moneyOffRuleInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动规则信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return moneyOffRuleInfo;
    }

    /**
     * 营销活动支付产品信息数据库实体类和接口实体类数据转换
     *
     * @param mcProductInfoBean 营销活动产品对象
     * @return cc.rengu.igas.momp.common.entity.TMMcProductInfo 营销活动产品信息表
     * @author Jinan Liu
     * @since 2020/4/1 21:06
     */
    private TMMcProductInfo convertMcProductInfo(McProductInfoBean mcProductInfoBean) {
        TMMcProductInfo mcProductInfo = new TMMcProductInfo();
        try {
            /* 法人机构号 */
            mcProductInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcProductInfo.setMcNo(globalMcNo);
            /* 业务产品代码 */
            mcProductInfo.setBizProdCode(mcProductInfoBean.getBizProdCode());
            /* 创建人 */
            mcProductInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcProductInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动支付产品信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcProductInfo;
    }

    /**
     * 新增营销活动信息
     *
     * @param dbsUtil                     数据为操作工具类
     * @param editMoneyOffMcDetailRequest 减免类营销活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:48
     */
    private void insertAllMcInfoByBank(DbsUtil dbsUtil, EditMoneyOffMcDetailRequest editMoneyOffMcDetailRequest) throws Exception {

        /* 营销活动基本信息新增 */
        TMMcMoneyOffInfo mcMoneyOffInfo = convertMcInfo(editMoneyOffMcDetailRequest.getMcInfoObj());
        /** 上传商户文件，活动审批状态修改为中间态 */
        if (merFileFlag) {
            /** 备份当前活动审批状态 */
            flowAuditStatus = mcMoneyOffInfo.getAuditStatus();
            /* 调整审批状态为任务处理中 */
            mcMoneyOffInfo.setAuditStatus(AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode());

        }
        insertMoMcInfo(dbsUtil, mcMoneyOffInfo);
        TMPlatBizTmp tmPlatBizTmp = convertMoMcInfoToTmp(mcMoneyOffInfo);
        if (merFileFlag) {
            /** 备份当前活动审批状态 */
            flowTmpAuditStatus = tmPlatBizTmp.getAuditStatus();
            /* 调整审批状态为任务处理中 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode());
            auditStatusChangeFlag = true;
        }
        insertTmpMoMcInfo(dbsUtil, tmPlatBizTmp);

        /* 营销活动机构信息新增 */
        List<TMMcOrgInfo> mcOrgInfoList = editMoneyOffMcDetailRequest.getOrgInfoList().stream().map(this::convertMcOrgInfo).collect(Collectors.toList());
        insertMcOrgInfo(dbsUtil, mcOrgInfoList);
        List<TMPlatBizTmp> tmpOrgList = mcOrgInfoList.stream().map(this::convertMcOrgInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpOrgList);
        /** 判断是否存在文件，存在则创建任务流水 */
        if (merFileFlag) {
            rglog.info("法人机构<{}>的营销活动<{}>同步创建营销活动任务信息!", globalInstId, globalMcNo);
            insertMcTaskInfoForMerFile(dbsUtil, editMoneyOffMcDetailRequest.getMrctFilePath());
        } else {
            /* 营销活动商户信息新增 */
            List<TMMcMchntInfo> tmMcMchntInfoList = null;
            if (CommonConstant.SPECIFIC_MCHNT_LIST.equals(mcMoneyOffInfo.getMerchantRange())) {
                /* 指定商户列表 */
                if (!CollectionUtils.isEmpty(editMoneyOffMcDetailRequest.getMchntInfoList())) {
                    tmMcMchntInfoList = editMoneyOffMcDetailRequest.getMchntInfoList().stream().map(this::convertMcMchntInfo).collect(Collectors.toList());
                }
            }
//        else if(CommonConstant.MCHNT_LAST_MONTH_AVG_DEPOSIT.equals(mcMoneyOffInfo.getMerchantRange())) {
//            /* 商户上月日均存款达标 */
//            tmMcMchntInfoList = fetchMchntInfoWithDeposit(editMoneyOffMcDetailRequest);
//
//        } else if(CommonConstant.MCHNT_LAST_MONTH_AVG_TXN_AMOUNT.equals(mcMoneyOffInfo.getMerchantRange())) {
//            /* 商户上月日均交易额达标 */
//            tmMcMchntInfoList = fetchMchntInfoWithTxnAmt(editMoneyOffMcDetailRequest);
//
//        } else {
//            /* 不支持的商户范围模式 */
//            rglog.error("法人机构<{}>的营销活动<{}>使用了不支持的商户范围模式<{}>!", globalInstId, globalMcNo, mcMoneyOffInfo.getMerchantRange());
//            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
//        }

            if (null == tmMcMchntInfoList || tmMcMchntInfoList.isEmpty()) {
                rglog.info("法人机构<{}>的营销活动<{}>无有效的参加营销活动的商户信息,无需插入数据!", globalInstId, globalMcNo);
            } else {
                /* 集合去重，排除接口上送重复数据问题 */
                tmMcMchntInfoList = tmMcMchntInfoList.stream().distinct().collect(Collectors.toList());

                /* 上传商户信息，需要判断商户新增/删除 */
                rglog.info("法人机构<{}>的营销活动<{}>编辑商户/商圈列表，size<{}>", globalInstId, globalMcNo, tmMcMchntInfoList.size());
                //商户列表，增量处理方式
                List<TMMcMchntInfo> mcMchntInfoList = tmMcMchntInfoList.stream().filter(item -> CommonConstant.ZERO_COMMON_CONSTANT.equals(item.getMchntType())).collect(Collectors.toList());
                rglog.info("法人机构<{}>的营销活动<{}>编辑商户列表，size<{}>", globalInstId, globalMcNo, mcMchntInfoList.size());

                /* 删除商户列表 */
                List<TMMcMchntInfo> delTmMcMchntList = mcMchntInfoList.stream().filter(item -> OprTypeEnum.DELETE.getOprTypeCode().equals(item.getOprType())).collect(Collectors.toList());
                rglog.info("法人机构<{}>的营销活动<{}>删除商户列表，size<{}>", globalInstId, globalMcNo, delTmMcMchntList.size());
                deleteMcMchntInfoList(dbsUtil, delTmMcMchntList);
                List<TMPlatBizTmp> delMcMchntList = delTmMcMchntList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
                rglog.info("法人机构<{}>的营销活动<{}>删除商户列表临时表，size<{}>", globalInstId, globalMcNo, delMcMchntList.size());
                deleteMultiMcDetialInfoByBank(dbsUtil, delMcMchntList);

                /* 新增商户列表 */
                List<TMMcMchntInfo> addTmMcMchntList = mcMchntInfoList.stream().filter(item -> OprTypeEnum.INSERT.getOprTypeCode().equals(item.getOprType())).collect(Collectors.toList());
                rglog.info("法人机构<{}>的营销活动<{}>保存商户列表，size<{}>", globalInstId, globalMcNo, addTmMcMchntList.size());
                insertMcMchntInfo(dbsUtil, addTmMcMchntList);
                List<TMPlatBizTmp> addTmpMchntList = addTmMcMchntList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
                rglog.info("法人机构<{}>的营销活动<{}>保存商户列表临时表，size<{}>", globalInstId, globalMcNo, addTmpMchntList.size());
                insertMultiMcDetialInfoByBank(dbsUtil, addTmpMchntList);

                /* 商圈列表，全量处理方式 */
                List<TMMcMchntInfo> tradeAreatList = tmMcMchntInfoList.stream().filter(item -> CommonConstant.ONE_COMMON_CONSTANT.equals(item.getMchntType())).collect(Collectors.toList());
                rglog.info("法人机构<{}>的营销活动<{}>保存商圈列表，size<{}>", globalInstId, globalMcNo, tradeAreatList.size());
                insertMcMchntInfo(dbsUtil, tradeAreatList);
                List<TMPlatBizTmp> tmpMchntList = tradeAreatList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
                rglog.info("法人机构<{}>的营销活动<{}>保存商圈列表临时表，size<{}>", globalInstId, globalMcNo, tmpMchntList.size());
                insertMultiMcDetialInfoByBank(dbsUtil, tmpMchntList);
            }
        }

        /* 营销活动用户信息新增 */
        if (CommonConstant.SPECIFIC_CLIENT_SUPPORT.equals(mcMoneyOffInfo.getClientRange())) {
            List<TMMcUserInfo> mcUserInfoList = editMoneyOffMcDetailRequest.getUserInfoList().stream().map(this::convertMcUserInfo).collect(Collectors.toList());
            insertMcUserInfo(dbsUtil, mcUserInfoList);
            List<TMPlatBizTmp> tmpUserList = mcUserInfoList.stream().map(this::convertMcUserInfoToTmp).collect(Collectors.toList());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpUserList);
        }

        /* 营销活动时间信息新增 */
        if (CommonConstant.SPECIFIC_TIME_SUPPORT.equals(mcMoneyOffInfo.getMcTimeFlag())) {
            List<TMMcTimeInfo> mcTimeInfoList = editMoneyOffMcDetailRequest.getTimeInfoList().stream().map(this::convertMcTimeInfo).collect(Collectors.toList());
            insertMcTimeInfo(dbsUtil, mcTimeInfoList);
            List<TMPlatBizTmp> tmpTimeList = mcTimeInfoList.stream().map(this::convertMcTimeInfoToTmp).collect(Collectors.toList());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpTimeList);
        }

        /* 营销活动规则信息新增 */
        List<TMMcMoneyOffRuleInfo> mcMoneyOffRuleInfoList = editMoneyOffMcDetailRequest.getRuleInfoList().stream().map(this::convertMcRuleInfo).collect(Collectors.toList());
        insertMcMoRuleInfo(dbsUtil, mcMoneyOffRuleInfoList);
        List<TMPlatBizTmp> tmpMoMcRuleList = mcMoneyOffRuleInfoList.stream().map(this::convertMoMcRuleInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpMoMcRuleList);

        /* 营销活动产品信息新增 */
        List<TMMcProductInfo> mcProductInfoList = editMoneyOffMcDetailRequest.getProductInfoList().stream().map(this::convertMcProductInfo).collect(Collectors.toList());
        insertMcProductInfo(dbsUtil, mcProductInfoList);
        List<TMPlatBizTmp> tmpProdList = mcProductInfoList.stream().map(this::convertMcProdInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpProdList);
    }

    /**
     * 保存数据流程
     *
     * @param xmlTreeUtil                 内部XML树
     * @param editMoneyOffMcDetailRequest 减免类营销活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020-06-29 18:50
     */
    private void saveAllMcInfoByBank(XmlTreeUtil xmlTreeUtil, EditMoneyOffMcDetailRequest editMoneyOffMcDetailRequest) throws Exception {

        int returnCode;

        /* 营销活动信息正式表查询 */
        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        TMMcMoneyOffInfo tmMcMoneyOffInfo = (TMMcMoneyOffInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, globalMcNo, TABLE_NAME);
        if (null == tmMcMoneyOffInfo) {
            rglog.error("法人机构<{}>的营销活动<{}>的信息不存在!");
            throw new BizException(RespCodeEnum.GET_MONEY_OFF_MC_DETAIL_ERROR.getRespCode(), RespCodeEnum.GET_MONEY_OFF_MC_DETAIL_ERROR.getRespDesc());
        }

        /* 营销活动信息临时表查询 */
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        TMPlatBizTmp tmPlatBizTmp = platBizTmpMapper.selectTmpMcInfo(globalInstId, globalMcNo, TABLE_NAME);
        if (null == tmPlatBizTmp) {
            rglog.error("法人机构<{}>的营销活动<{}>的信息不存在!");
            throw new BizException(RespCodeEnum.GET_MONEY_OFF_MC_DETAIL_ERROR.getRespCode(), RespCodeEnum.GET_MONEY_OFF_MC_DETAIL_ERROR.getRespDesc());
        }

        /* 数据库有历史数据，需要判断历史数据状态 */

        /* 判断营销活动是否存在进行中跑批任务 */
        if (AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode().equals(tmMcMoneyOffInfo.getAuditStatus())) {
            /* 营销活动审批状态异常，不可保存数据 */
            rglog.error("法人机构<{}>的营销活动<{}>的审批状态<{}>，存在跑批任务，不可保存数据!", globalInstId, globalMcNo, tmMcMoneyOffInfo.getAuditStatus());
            throw new BizException(RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespDesc());
        }

        /* 判断营销活动审批状态 */
        if (!AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode().equals(tmPlatBizTmp.getAuditStatus()) &&
                !AuditStatusEnum.NEW_AUDIT_REJECT.getAuditStatusCode().equals(tmPlatBizTmp.getAuditStatus()) &&
                !AuditStatusEnum.MODIFY_AUDIT_REJECT.getAuditStatusCode().equals(tmPlatBizTmp.getAuditStatus()) &&
                !AuditStatusEnum.PUBLISH_AUDIT_REJECT.getAuditStatusCode().equals(tmPlatBizTmp.getAuditStatus())) {
            /* 营销活动审批状态异常，不可保存数据 */
            rglog.error("法人机构<{}>的营销活动<{}>的审批状态<{}>异常，不可保存数据!", globalInstId, globalMcNo, tmPlatBizTmp.getAuditStatus());
            throw new BizException(RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespDesc());
        }

        /* 开启数据库事务 */
        String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        dbsUtil.dbsBeginTransaction();

        String tmpAuditStatus = tmPlatBizTmp.getAuditStatus();
        String tmpMcStatus = tmPlatBizTmp.getMcStatus();
        String tmpBizStatus = tmPlatBizTmp.getBizStatus();

        String auditStatus = tmMcMoneyOffInfo.getAuditStatus();
        String mcStatus = tmMcMoneyOffInfo.getMcStatus();

        if (McStatusEnum.PROGRESSING.getMcStatusCode().equals(mcStatus)) {
            /* 正式表营销活动状态是进行中，说明是进行中活动添加商户流程，只更新临时表数据 */
            if (merFileFlag) {
                rglog.error("营销活动状态为进行中,禁止上传商户文件");
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }

            updateAllDraftMcInfoByBank(dbsUtil, editMoneyOffMcDetailRequest);

        } else {
            /* 正式表营销活动状态不是进行中，正式表临时表一起更新 */
            updateAllMcInfoByBank(dbsUtil, editMoneyOffMcDetailRequest);
            /* 更新定时任务流水业务数据 */
            if (merFileFlag) {

                /** 按照原流程更新临时表除活动信息外的其他表信息 */
                rglog.info("merFileFlagBak begin ,更新临时表中除活动表信息外的其他信息");
                returnCode = platBizTmpMapper.updateTmpMcOtherStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, TABLE_NAME,
                        tmpBizStatus, tmpMcStatus, tmpAuditStatus, AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), globalOprId, globalTimeStamp);
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新临时表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动其他信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }

                /* 备份活动表、临时表业务数据，跑批完成后进行状态还原操作 */
                //备份更新后活动审批状态
                rglog.info("任务流水<{}>更新活动状态，备份原始状态,活动表<{}>,临时表<{}>", globalFlowNo, auditStatus, tmpAuditStatus);
                JSONObject bizDate = new JSONObject();
                bizDate.put("auditStatus", auditStatus);
                bizDate.put("tmpAuditStatus", tmpAuditStatus);
                rglog.info("交易流水号：<{}>,任务流水号<{}>,switch-1,备份原营销活动审批状态<{}>", traceNo, globalFlowNo, bizDate.toString());
                /* 更新任务表业务数据信息 */
                updateMcTaskInfoBizDate(dbsUtil, globalInstId, globalMcNo, globalFlowNo, bizDate.toString());

                //变更活动表、临时表审批状态为中间态
                auditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                tmpAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                rglog.info("任务流水<{}>更新活动状态，更新最新状态,活动表<{}>,临时表<{}>", globalFlowNo, auditStatus, tmpAuditStatus);
                String oldAuditStatus = AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode();
                if (auditStatusChangeFlag) {
                    oldAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                }
                /** 更新临时表活动信息的信息 */
                returnCode = platBizTmpMapper.updateTmpMcInfoStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, TABLE_NAME,
                        tmpBizStatus, tmpMcStatus, tmpAuditStatus, oldAuditStatus, globalOprId, globalTimeStamp);
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新临时表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动活动信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }

            } else {
                //原流程更新临时表状态
                returnCode = platBizTmpMapper.updateTmpMcAllStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, tmpBizStatus, tmpMcStatus, tmpAuditStatus, AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), globalOprId, globalTimeStamp);
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新临时表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
            }

            /* 更新正式表审批状态 */
            TMMcMoneyOffInfo tmMcMoneyOffInfo1 = new TMMcMoneyOffInfo();
            tmMcMoneyOffInfo1.setInstId(globalInstId);
            tmMcMoneyOffInfo1.setMcNo(globalMcNo);
            tmMcMoneyOffInfo1.setMcStatus(mcStatus);
            tmMcMoneyOffInfo1.setAuditStatus(auditStatus);
            tmMcMoneyOffInfo1.setLastOprId(globalOprId);
            tmMcMoneyOffInfo1.setUpdateTime(globalTimeStamp);

            returnCode = mcDetailInfoMapper.updateMcStatusForPublishing(tmMcMoneyOffInfo1, TABLE_NAME);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 更新正式表中营销活动审批状态失败 */
                dbsUtil.dbsEndTransaction(false);
                rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
            }
        }

        /* 正常结束数据库事务 */
        dbsUtil.dbsEndTransaction(true);
    }

    /**
     * 更新营销活动信息
     *
     * @param editMoneyOffMcDetailRequest 减免类营销活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/4/2 00:13
     */
    private void updateAllMcInfoByBank(DbsUtil dbsUtil, EditMoneyOffMcDetailRequest editMoneyOffMcDetailRequest) throws Exception {

        //删除指定营销活动编号的所有数据
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        rglog.info("法人机构<{}>的营销活动<{}>删除临时表数据，仅保留商户信息");
        int returnCode = platBizTmpMapper.deleteTmpMcDataRetainMchntListByMcNo(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 删除临时表数据失败 */
            dbsUtil.dbsEndTransaction(false);
            rglog.error("删除临时表中营销活动各信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            throw new BizException(RespCodeEnum.DELETE_TMP_MC_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_TMP_MC_DATA_ERROR.getRespDesc());
        }
        /* 营销活动信息更新 */
        TMMcMoneyOffInfo tmMcMoneyOffInfo = convertMcInfo(editMoneyOffMcDetailRequest.getMcInfoObj());
        deleteMoMcInfo(dbsUtil);
        if (merFileFlag) {
            /** 备份当前活动审批状态 */
            flowAuditStatus = tmMcMoneyOffInfo.getAuditStatus();
            /* 调整审批状态为任务处理中 */
            tmMcMoneyOffInfo.setAuditStatus(AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode());
        }
        insertMoMcInfo(dbsUtil, tmMcMoneyOffInfo);
        TMPlatBizTmp tmPlatBizTmp = convertMoMcInfoToTmp(tmMcMoneyOffInfo);
        if (merFileFlag) {
            /** 备份当前活动审批状态 */
            flowTmpAuditStatus = tmPlatBizTmp.getAuditStatus();
            /* 调整审批状态为任务处理中 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode());
            auditStatusChangeFlag = true;
        }
        insertTmpMoMcInfo(dbsUtil, tmPlatBizTmp);
        /* 处理因机构变更需要清除的商户数据 */
        delMchntListByDelOrgList(dbsUtil, editMoneyOffMcDetailRequest.getOrgInfoList());
        /* 营销活动机构信息更新 */
        List<TMMcOrgInfo> mcOrgInfoList = editMoneyOffMcDetailRequest.getOrgInfoList().stream().map(this::convertMcOrgInfo).collect(Collectors.toList());
        deleteMcOrgInfo(dbsUtil);
        insertMcOrgInfo(dbsUtil, mcOrgInfoList);
        List<TMPlatBizTmp> tmpOrgList = mcOrgInfoList.stream().map(this::convertMcOrgInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpOrgList);
        /** 上传商户文件，创建定时任务 */
        if (merFileFlag) {
            /** 新增任务流水 */
            rglog.info("法人机构<{}>的营销活动<{}>同步创建营销活动任务信息!", globalInstId, globalMcNo);
            insertMcTaskInfoForMerFile(dbsUtil, editMoneyOffMcDetailRequest.getMrctFilePath());
        } else {
            /* 营销活动商户信息更新 */
            List<TMMcMchntInfo> tmMcMchntInfoList = new ArrayList<>();
            if (CommonConstant.SPECIFIC_MCHNT_LIST.equals(tmMcMoneyOffInfo.getMerchantRange())) {
                /* 指定商户列表 */
                tmMcMchntInfoList = editMoneyOffMcDetailRequest.getMchntInfoList().stream().map(this::convertMcMchntInfo).collect(Collectors.toList());

            }
            //        else if(CommonConstant.MCHNT_LAST_MONTH_AVG_DEPOSIT.equals(tmMcMoneyOffInfo.getMerchantRange())) {
            //            /* 商户上月日均存款达标 */
            //            tmMcMchntInfoList = fetchMchntInfoWithDeposit(editMoneyOffMcDetailRequest);
            //
            //        } else if(CommonConstant.MCHNT_LAST_MONTH_AVG_TXN_AMOUNT.equals(tmMcMoneyOffInfo.getMerchantRange())) {
            //            /* 商户上月日均交易额达标 */
            //            tmMcMchntInfoList = fetchMchntInfoWithTxnAmt(editMoneyOffMcDetailRequest);
            //
            //        } else {
            //            /* 不支持的商户范围模式 */
            //            rglog.error("法人机构<{}>的营销活动<{}>使用了不支持的商户范围模式<{}>!", globalInstId, globalMcNo, tmMcMoneyOffInfo.getMerchantRange());
            //            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            //        }
            /** 商户增量处理，商圈全量处理 */
            rglog.info("法人机构<{}>的营销活动<{}>编辑商户/商圈列表，size<{}>", globalInstId, globalMcNo, tmMcMchntInfoList.size());
            /* 商户列表，增量处理方式 */
            List<TMMcMchntInfo> mcMchntInfoList = tmMcMchntInfoList.stream().filter(item -> CommonConstant.ZERO_COMMON_CONSTANT.equals(item.getMchntType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>编辑商户列表，size<{}>", globalInstId, globalMcNo, mcMchntInfoList.size());

            /* 删除商户列表 */
            List<TMMcMchntInfo> delTmMcMchntList = mcMchntInfoList.stream().filter(item -> OprTypeEnum.DELETE.getOprTypeCode().equals(item.getOprType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>删除商户列表，size<{}>", globalInstId, globalMcNo, delTmMcMchntList.size());
            deleteMcMchntInfoList(dbsUtil, delTmMcMchntList);
            List<TMPlatBizTmp> delMcMchntList = delTmMcMchntList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>删除商户列表临时表，size<{}>", globalInstId, globalMcNo, delMcMchntList.size());
            deleteMultiMcDetialInfoByBank(dbsUtil, delMcMchntList);

            /* 新增商户列表 */
            List<TMMcMchntInfo> addTmMcMchntList = mcMchntInfoList.stream().filter(item -> OprTypeEnum.INSERT.getOprTypeCode().equals(item.getOprType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商户列表，size<{}>", globalInstId, globalMcNo, addTmMcMchntList.size());
            insertMcMchntInfo(dbsUtil, addTmMcMchntList);
            List<TMPlatBizTmp> addTmpMchntList = addTmMcMchntList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商户列表临时表，size<{}>", globalInstId, globalMcNo, addTmpMchntList.size());
            insertMultiMcDetialInfoByBank(dbsUtil, addTmpMchntList);

            /* 商圈列表，全量处理方式 */
            //删除原有商圈
            rglog.info("法人机构<{}>的营销活动<{}>删除下属所有商圈数据。", globalInstId, globalMcNo);
            deleteMcMchntAreat(dbsUtil, CommonConstant.ONE_COMMON_CONSTANT);
            //新增商圈数据
            List<TMMcMchntInfo> tradeAreatList = tmMcMchntInfoList.stream().filter(item -> CommonConstant.ONE_COMMON_CONSTANT.equals(item.getMchntType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商圈列表，size<{}>", tradeAreatList.size());
            insertMcMchntInfo(dbsUtil, tradeAreatList);
            List<TMPlatBizTmp> tmpMchntList = tradeAreatList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商圈列表临时表，size<{}>", tmpMchntList.size());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpMchntList);

        }

        /* 营销活动用户信息更新 */
        List<TMMcUserInfo> mcUserInfoList = editMoneyOffMcDetailRequest.getUserInfoList().stream().map(this::convertMcUserInfo).collect(Collectors.toList());
        deleteMcUserInfo(dbsUtil);
        insertMcUserInfo(dbsUtil, mcUserInfoList);
        List<TMPlatBizTmp> tmpUserList = mcUserInfoList.stream().map(this::convertMcUserInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpUserList);

        /* 营销活动时间信息更新 */
        List<TMMcTimeInfo> mcTimeInfoList = editMoneyOffMcDetailRequest.getTimeInfoList().stream().map(this::convertMcTimeInfo).collect(Collectors.toList());
        deleteMcTimeInfo(dbsUtil);
        insertMcTimeInfo(dbsUtil, mcTimeInfoList);
        List<TMPlatBizTmp> tmpTimeList = mcTimeInfoList.stream().map(this::convertMcTimeInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpTimeList);

        /* 营销活动规则信息更新 */
        List<TMMcMoneyOffRuleInfo> mcMoneyOffRuleInfoList = editMoneyOffMcDetailRequest.getRuleInfoList().stream().map(this::convertMcRuleInfo).collect(Collectors.toList());
        deleteMcMoRuleInfo(dbsUtil);
        insertMcMoRuleInfo(dbsUtil, mcMoneyOffRuleInfoList);
        List<TMPlatBizTmp> tmpMoMcRuleList = mcMoneyOffRuleInfoList.stream().map(this::convertMoMcRuleInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpMoMcRuleList);

        /* 营销活动产品信息更新 */
        List<TMMcProductInfo> mcProductInfoList = editMoneyOffMcDetailRequest.getProductInfoList().stream().map(this::convertMcProductInfo).collect(Collectors.toList());
        deleteMcProductInfo(dbsUtil);
        insertMcProductInfo(dbsUtil, mcProductInfoList);
        List<TMPlatBizTmp> tmpProdList = mcProductInfoList.stream().map(this::convertMcProdInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpProdList);
    }


    /**
     * 提交营销活动信息
     *
     * @param editMoneyOffMcDetailRequest 减免类营销活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/4/6 17:43
     */
    private void submitMcInfo(EditMoneyOffMcDetailRequest editMoneyOffMcDetailRequest) throws Exception {

        int returnCode = 0;
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        rglog.info("提交审批流程开始");

        /* 营销活动信息正式表查询 */
        TMMcMoneyOffInfo tmMcMoneyOffInfo = null;
        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();

        TMMcMoneyOffInfo mcMoneyOffInfo = convertMcInfo(editMoneyOffMcDetailRequest.getMcInfoObj());
        if (StringUtil.isNullorEmpty(globalMcNo)) {
            rglog.info("上送数据无营销活动编号!");
        } else {
            tmMcMoneyOffInfo = (TMMcMoneyOffInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, globalMcNo, TABLE_NAME);
        }

        /* 营销活动信息临时表查询 */
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        TMPlatBizTmp platBizTmp = platBizTmpMapper.selectTmpMcInfo(globalInstId, globalMcNo, TABLE_NAME);

        /* 开启数据库事务 */
        String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        dbsUtil.dbsBeginTransaction();

        if (null == tmMcMoneyOffInfo && null == platBizTmp) {

            /* 数据库无历史数据，新增提交审批场景，新增数据后直接提交审批 */

            /*
             * 如果营销活动编号不存在，说明是全新的营销活动，需要生成一个营销活动编号，并新增全部数据；
             * 如果营销活动编号存在，说明是接口调用错误，需要返回失败信息；
             */
            if (StringUtil.isNullorEmpty(globalMcNo)) {
                /* 生成营销活动编号 */
                globalMcNo = generateNewMcNo(editMoneyOffMcDetailRequest.getMcInfoObj());
                if (!StringUtil.isNullorEmpty(globalMcNo)) {
                    rglog.info("MC_NO=<{}>", globalMcNo);
                }

                /* 全部新增流程，插入数据 */
                rglog.info("提交审批新增流程开始");
                insertAllMcInfoByBank(dbsUtil, editMoneyOffMcDetailRequest);
            } else {
                /* 全部更新流程，更新数据 */
                rglog.error("当前营销活动<{}>不可保存数据!", globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());
            }

            if (merFileFlag) {
                returnCode = platBizTmpMapper.updateTmpMcOtherAuditStatusByPrimaryKey(globalInstId, globalMcNo, TABLE_NAME,
                        AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode(), BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新临时表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动其他信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
                /* 备份活动表、临时表业务数据，任务完成后还原审批状态 */
                JSONObject bizDate = new JSONObject();
                bizDate.put("auditStatus", AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode());
                bizDate.put("tmpAuditStatus", AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode());
                rglog.info("交易流水号：<{}>,任务流水号<{}>,switch-2,备份原营销活动审批状态<{}>", traceNo, globalFlowNo, bizDate.toString());
                /* 更新任务表业务数据信息 */
                updateMcTaskInfoBizDate(dbsUtil, globalInstId, globalMcNo, globalFlowNo, bizDate.toString());

                String oldAuditStatus = AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode();
                if (auditStatusChangeFlag) {
                    oldAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                }
                /* 更新临时表活动审批状态 */
                returnCode = platBizTmpMapper.updateTmpMcInfoAuditStatusByPrimaryKey(globalInstId, globalMcNo, TABLE_NAME,
                        oldAuditStatus, AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode(), BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新正式表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动活动信息审批状态失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                }

                /* 更新正式表审批状态 */
                returnCode = mcDetailInfoMapper.updateMoneyOffMcAuditStatusByPrimaryKeyForTask(globalInstId, globalMcNo, AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新正式表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
            } else {
                /* 更新临时表审批状态 */
                returnCode = platBizTmpMapper.updateTmpMcAuditStatusByPrimaryKey(globalInstId, globalMcNo, AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode(), BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新临时表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }

                /* 更新正式表审批状态 */
                returnCode = mcDetailInfoMapper.updateMoneyOffMcAuditStatusByPrimaryKey(globalInstId, globalMcNo, AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新正式表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
            }

            /* 正常结束数据库事务 */
            dbsUtil.dbsEndTransaction(true);

        } else if (null != tmMcMoneyOffInfo && null != platBizTmp) {
            /* 数据库有历史数据，需要判断历史数据状态 */

            /* 判断活动审批状态，是否存在未完成任务 */
            if (AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode().equals(platBizTmp.getAuditStatus())) {
                /* 不可提交审批状态 */
                rglog.error("定时任务处理中，营销活动是不可提交审批状态,不可提交审批, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespDesc());
            }

            /* 判断营销活动审批状态 */
            if (!AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode().equals(platBizTmp.getAuditStatus()) &&
                    !AuditStatusEnum.NEW_AUDIT_REJECT.getAuditStatusCode().equals(platBizTmp.getAuditStatus()) &&
                    !AuditStatusEnum.MODIFY_AUDIT_REJECT.getAuditStatusCode().equals(platBizTmp.getAuditStatus()) &&
                    !AuditStatusEnum.PUBLISH_AUDIT_REJECT.getAuditStatusCode().equals(platBizTmp.getAuditStatus())) {
                /* 不可提交审批状态 */
                rglog.error("营销活动是不可提交审批状态,不可提交审批, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespDesc());
            }

            /* 判断业务状态 */
            if (BizStatusEnum.TMP_STATUS.getBizStatusCode().equals(platBizTmp.getBizStatus())) {
                if (!McStatusEnum.DRAFT.getMcStatusCode().equals(platBizTmp.getMcStatus()) &&
                        !McStatusEnum.NOT_PUBLISHED.getMcStatusCode().equals(platBizTmp.getMcStatus())) {
                    /* 营销活动状态异常，不可提交审批 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("营销活动状态异常，不可提交审批, MC_STATUS=<{}>, MC_NO=<{}>", platBizTmp.getMcStatus(), globalMcNo);
                    throw new BizException(RespCodeEnum.WRONG_MC_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_MC_STATUS_TO_SUBMIT_ERROR.getRespDesc());
                } else {
                    /* 新增提交审批场景 */

                    /*
                     * 如果营销活动编号不存在，说明数据异常，不可提交审批；
                     * 如果营销活动编号存在，说明是正常的新增提交审批场景，可以提交审批；
                     */
                    if (StringUtil.isNullorEmpty(globalMcNo)) {
                        /* 全部更新流程，更新数据 */
                        rglog.error("当前营销活动<{}>不可保存数据!", globalMcNo);
                        dbsUtil.dbsEndTransaction(false);
                        throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());

                    } else {
                        /* 全部更新流程，更新数据 */
                        updateAllMcInfoByBank(dbsUtil, editMoneyOffMcDetailRequest);
                    }

                    //更新活动新状态
                    String newAuditStatus = "";
                    if ((McStatusEnum.DRAFT.getMcStatusCode().equals(platBizTmp.getMcStatus()) && AuditStatusEnum.NEW_AUDIT_REJECT.getAuditStatusCode().equals(platBizTmp.getAuditStatus())) || (McStatusEnum.DRAFT.getMcStatusCode().equals(platBizTmp.getMcStatus()) && AuditStatusEnum.MODIFY_AUDIT_REJECT.getAuditStatusCode().equals(platBizTmp.getAuditStatus()))) {
                        newAuditStatus = AuditStatusEnum.MODIFY_AUDIT_PROCESSING.getAuditStatusCode();
                    } else {
                        newAuditStatus = AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode();
                    }

                    String auditStatus = newAuditStatus;
                    String tmpAuditStatus = AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode();

                    if (merFileFlag) {
                        /* 更新临时表除活动信息外其他数据审批状态 */
                        returnCode = platBizTmpMapper.updateTmpMcOtherAuditStatusByPrimaryKey(globalInstId, globalMcNo, TABLE_NAME,
                                tmpAuditStatus, newAuditStatus, BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                        if (Database.DBS_SUCCESS != returnCode) {
                            /* 更新临时表中营销活动审批状态失败 */
                            dbsUtil.dbsEndTransaction(false);
                            rglog.error("更新临时表中营销活动其他信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                            throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                        }

                        /* 备份活动表、临时表业务数据，任务完成后还原审批状态 */
                        JSONObject bizDate = new JSONObject();
                        bizDate.put("auditStatus", auditStatus);
                        bizDate.put("tmpAuditStatus", newAuditStatus);
                        rglog.info("交易流水号：<{}>,任务流水号<{}>,switch-3,备份原营销活动审批状态<{}>", traceNo, globalFlowNo, bizDate.toString());
                        auditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                        newAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                        /* 更新任务表业务数据信息 */
                        updateMcTaskInfoBizDate(dbsUtil, globalInstId, globalMcNo, globalFlowNo, bizDate.toString());

                        if (auditStatusChangeFlag) {
                            tmpAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                        }
                        /* 更新临时表活动信息审批状态 */
                        returnCode = platBizTmpMapper.updateTmpMcInfoAuditStatusByPrimaryKey(globalInstId, globalMcNo, TABLE_NAME,
                                tmpAuditStatus, newAuditStatus, BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                        if (Database.DBS_SUCCESS != returnCode) {
                            /* 更新临时表中营销活动审批状态失败 */
                            dbsUtil.dbsEndTransaction(false);
                            rglog.error("更新临时表中营销活动活动信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                            throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                        }

                        /* 更新正式表审批状态 */
                        returnCode = mcDetailInfoMapper.updateMoneyOffMcAuditStatusByPrimaryKeyForTask(globalInstId, globalMcNo, auditStatus);
                        if (Database.DBS_SUCCESS != returnCode) {
                            /* 更新正式表中营销活动审批状态失败 */
                            dbsUtil.dbsEndTransaction(false);
                            rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                            throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                        }

                    } else {
                        /* 更新临时表审批状态 */
                        returnCode = platBizTmpMapper.updateTmpMcAuditStatusByPrimaryKey(globalInstId, globalMcNo, tmpAuditStatus, newAuditStatus, BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                        if (Database.DBS_SUCCESS != returnCode) {
                            /* 更新临时表中营销活动审批状态失败 */
                            dbsUtil.dbsEndTransaction(false);
                            rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                            throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                        }

                        /* 更新正式表审批状态 */
                        returnCode = mcDetailInfoMapper.updateMoneyOffMcAuditStatusByPrimaryKey(globalInstId, globalMcNo, auditStatus);
                        if (Database.DBS_SUCCESS != returnCode) {
                            /* 更新正式表中营销活动审批状态失败 */
                            dbsUtil.dbsEndTransaction(false);
                            rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                            throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                        }
                    }


                }

            } else if (BizStatusEnum.NORMAL_STATUS.getBizStatusCode().equals(platBizTmp.getBizStatus())) {
                if (McStatusEnum.NOT_PUBLISHED.getMcStatusCode().equals(platBizTmp.getMcStatus()) && McStatusEnum.NOT_PUBLISHED.getMcStatusCode().equals(tmMcMoneyOffInfo.getMcStatus())) {
                    /* 修改提交审批场景 */
                    /*
                     * 如果营销活动编号不存在，说明数据异常，不可提交审批；
                     * 如果营销活动编号存在，说明是正常的新增提交审批场景，可以提交审批；
                     */
                    if (StringUtil.isNullorEmpty(globalMcNo)) {
                        /* 全部更新流程，更新数据 */
                        rglog.error("当前营销活动<{}>不可保存数据!", globalMcNo);
                        dbsUtil.dbsEndTransaction(false);
                        throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());

                    } else {
                        /* 全部更新流程，更新数据 */
//                        String tmpAuditStatus = platBizTmp.getAuditStatus();
                        String tmpMcStatus = platBizTmp.getMcStatus();
                        String tmpBizStatus = platBizTmp.getBizStatus();

//                        String auditStatus = tmMcMoneyOffInfo.getAuditStatus();
//                        String mcStatus = tmMcMoneyOffInfo.getMcStatus();

                        updateAllMcInfoByBank(dbsUtil, editMoneyOffMcDetailRequest);

                        String auditStatus = AuditStatusEnum.MODIFY_AUDIT_PROCESSING.getAuditStatusCode();
                        String tmpAuditStatus = AuditStatusEnum.MODIFY_AUDIT_PROCESSING.getAuditStatusCode();
                        String oldAuditStatus = AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode();
                        if (merFileFlag) {
                            /* 更新临时表除活动信息外其他数据审批状态 */
                            returnCode = platBizTmpMapper.updateTmpMcOtherStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, TABLE_NAME,
                                    tmpBizStatus, tmpMcStatus, tmpAuditStatus, oldAuditStatus, globalOprId, globalTimeStamp);
                            if (Database.DBS_SUCCESS != returnCode) {
                                /* 更新临时表中营销活动审批状态失败 */
                                dbsUtil.dbsEndTransaction(false);
                                rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                                throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                            }

                            /* 备份活动表、临时表业务数据，任务完成后还原审批状态 */
                            JSONObject bizDate = new JSONObject();
                            rglog.info("任务流水<{}>更新活动状态，备份原始状态,活动表<{}>,临时表<{}>", globalFlowNo, auditStatus, tmpAuditStatus);
                            bizDate.put("auditStatus", auditStatus);
                            bizDate.put("tmpAuditStatus", tmpAuditStatus);
                            rglog.info("交易流水号：<{}>,任务流水号<{}>,switch-4,备份原营销活动审批状态<{}>", traceNo, globalFlowNo, bizDate.toString());
                            auditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                            tmpAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();

                            rglog.info("任务流水<{}>更新活动状态，更新最新状态,活动表<{}>,临时表<{}>", globalFlowNo, auditStatus, tmpAuditStatus);
                            /* 更新任务表业务数据信息 */
                            updateMcTaskInfoBizDate(dbsUtil, globalInstId, globalMcNo, globalFlowNo, bizDate.toString());

                            if (auditStatusChangeFlag) {
                                oldAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                            }
                            /* 更新临时表活动信息审批状态 */
                            returnCode = platBizTmpMapper.updateTmpMcInfoStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, TABLE_NAME,
                                    tmpBizStatus, tmpMcStatus, tmpAuditStatus, oldAuditStatus, globalOprId, globalTimeStamp);
                            if (Database.DBS_SUCCESS != returnCode) {
                                /* 更新临时表中营销活动审批状态失败 */
                                dbsUtil.dbsEndTransaction(false);
                                rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                                throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                            }
                        } else {
                            /* 更新临时表审批状态 */
                            returnCode = platBizTmpMapper.updateTmpMcAllStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, tmpBizStatus, tmpMcStatus, tmpAuditStatus, oldAuditStatus, globalOprId, globalTimeStamp);
                            if (Database.DBS_SUCCESS != returnCode) {
                                /* 更新临时表中营销活动审批状态失败 */
                                dbsUtil.dbsEndTransaction(false);
                                rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                                throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                            }
                        }

                        /* 更新正式表审批状态 */
                        TMMcMoneyOffInfo tmMcMoneyOffInfo1 = new TMMcMoneyOffInfo();
                        tmMcMoneyOffInfo1.setInstId(globalInstId);
                        tmMcMoneyOffInfo1.setMcNo(globalMcNo);
                        tmMcMoneyOffInfo1.setMcStatus(McStatusEnum.NOT_PUBLISHED.getMcStatusCode());
                        tmMcMoneyOffInfo1.setAuditStatus(auditStatus);
                        tmMcMoneyOffInfo1.setLastOprId(globalOprId);
                        tmMcMoneyOffInfo1.setUpdateTime(globalTimeStamp);

                        returnCode = mcDetailInfoMapper.updateMcStatusForPublishing(tmMcMoneyOffInfo1, TABLE_NAME);
                        if (Database.DBS_SUCCESS != returnCode) {
                            /* 更新正式表中营销活动审批状态失败 */
                            dbsUtil.dbsEndTransaction(false);
                            rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                            throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                        }
                    }
                } else if (McStatusEnum.PROGRESSING.getMcStatusCode().equals(platBizTmp.getMcStatus()) && McStatusEnum.PROGRESSING.getMcStatusCode().equals(tmMcMoneyOffInfo.getMcStatus())) {
                    /* 活动中添加商户场景 */
                    //判断是否上传商户文件
                    if (merFileFlag) {
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("进行中营销活动禁止上传商户文件!");
                        throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
                    }
                    //判断上送的商户信息是否已经存在
                    McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
                    //取正式表进行中新增的商户
                    List<TMMcMchntInfo> tmMcMchntInfoListing = mcMchntInfoMapper.selectMcMchntInfoList(globalInstId, globalMcNo);
                    //编辑或新增上送的商户信息
                    List<TMMcMchntInfo> tmMcMchntInfoList = editMoneyOffMcDetailRequest.getMchntInfoList().stream().map(this::convertMcMchntInfos).collect(Collectors.toList());
                    //要删除的商户List
                    List<TMMcMchntInfo> deleteMchntList;
                    deleteMchntList = tmMcMchntInfoListing;
                    for (TMMcMchntInfo tmMcMchntInfo : tmMcMchntInfoList) {
                        deleteMchntList = deleteMchntList.stream().filter(item -> !item.getMchntNo().equals(tmMcMchntInfo.getMchntNo())).collect(Collectors.toList());
                    }
                    //正式表删除商户信息
                    for (TMMcMchntInfo tmMcMchntInfo : deleteMchntList) {
                        returnCode = mcMchntInfoMapper.deleteMchntInfo(tmMcMchntInfo.getInstId(), tmMcMchntInfo.getMcNo(), tmMcMchntInfo.getMchntNo());
                        if (Database.DBS_SUCCESS != returnCode) {
                            dbsUtil.dbsEndTransaction(false);
                            rglog.error("正式表删除商户失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, tmMcMchntInfo.getMcNo());
                            throw new BizException(RespCodeEnum.DELETE_MC_MCHNT_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_MC_MCHNT_DATA_ERROR.getRespDesc());
                        }
                    }
                    //临时表删除商户信息
                    List<TMPlatBizTmp> deletetmPlatBizTmpList = deleteMchntList.stream().map(this::convertMcMchntInfoToTmps).collect(Collectors.toList());
                    returnCode = platBizTmpMapper.deleteByMcNoMchntNoTablename(deletetmPlatBizTmpList);
                    if (Database.DBS_SUCCESS != returnCode) {
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("临时删除商户失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                        throw new BizException(RespCodeEnum.DELETE_MC_MCHNT_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_MC_MCHNT_DATA_ERROR.getRespDesc());
                    }
                    //要新增的商户list
                    List<TMMcMchntInfo> newMchntList;
                    newMchntList = tmMcMchntInfoList;
                    for (TMMcMchntInfo tmMcMchntInfo : tmMcMchntInfoListing) {
                        newMchntList = newMchntList.stream().filter(item -> !item.getMchntNo().equals(tmMcMchntInfo.getMchntNo())).collect(Collectors.toList());
                    }
                    //插入正式表新增商户
                    returnCode = mcMchntInfoMapper.insertMcMchntInfoListByBank(newMchntList);
                    if (Database.DBS_SUCCESS != returnCode) {
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("正式表插入新增商户失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                        throw new BizException(RespCodeEnum.WRONG_UPDATEMCMCHNT_ERROR.getRespCode(), RespCodeEnum.WRONG_UPDATEMCMCHNT_ERROR.getRespDesc());
                    }
                    //插入临时表新增商户
                    List<TMPlatBizTmp> tmPlatBizTmpList = newMchntList.stream().map(this::convertMcMchntInfoToTmps).collect(Collectors.toList());
                    returnCode = platBizTmpMapper.insertMchntDataForUnderwayMc(tmPlatBizTmpList);
                    if (Database.DBS_SUCCESS != returnCode) {
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("临时表插入新增商户失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                        throw new BizException(RespCodeEnum.WRONG_UPDATEMCMCHNT_ERROR.getRespCode(), RespCodeEnum.WRONG_UPDATEMCMCHNT_ERROR.getRespDesc());
                    }
                    /* 更新临时表审批状态 */
                    /* 修改临时表营销活动状态 */
                    TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();
                    tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
                    tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
                    tmPlatBizTmp.setAuditStatus(AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode());
                    tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_MO_INFO.getTableNameDesc());
                    tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MO_INFO.getTableNameCode());
                    returnCode = platBizTmpMapper.updataTMPlatBizByinstIdMcNoTableNameAuditStatus(globalInstId, globalMcNo, tmPlatBizTmp, platBizTmp.getAuditStatus(), globalOprId, new SimpleDateFormat(CommonConstant.TIMESTAMP_FORMAT).format(new Date()));
                    if (Database.DBS_SUCCESS != returnCode) {
                        /* 更新临时表中营销活动审批状态失败 */
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                        throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                    }
                    /* 更新正式表审批状态 */
                    TMMcMoneyOffInfo tmMcMoneyOffInfo1 = new TMMcMoneyOffInfo();
                    tmMcMoneyOffInfo1.setInstId(globalInstId);
                    tmMcMoneyOffInfo1.setMcNo(globalMcNo);
                    tmMcMoneyOffInfo1.setMcStatus(McStatusEnum.PROGRESSING.getMcStatusCode());
                    tmMcMoneyOffInfo1.setAuditStatus(AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode());
                    tmMcMoneyOffInfo1.setLastOprId(globalOprId);
                    tmMcMoneyOffInfo1.setUpdateTime(globalTimeStamp);

                    returnCode = mcDetailInfoMapper.updateMcStatusForPublishing(tmMcMoneyOffInfo1, TABLE_NAME);
                    if (Database.DBS_SUCCESS != returnCode) {
                        /* 更新正式表中营销活动审批状态失败 */
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                        throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                    }

                } else {
                    /* 营销活动状态异常，不可提交审批 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("营销活动状态异常，不可提交审批, MC_STATUS=<{}>, MC_NO=<{}>", platBizTmp.getMcStatus(), globalMcNo);
                    throw new BizException(RespCodeEnum.WRONG_MC_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_MC_STATUS_TO_SUBMIT_ERROR.getRespDesc());
                }
            } else {
                /* 临时表状态异常，不可提交审批 */
                dbsUtil.dbsEndTransaction(false);
                rglog.error("营销活动临时数据状态异常，不可提交审批, BIZ_STATUS=<{}>, MC_NO=<{}>", platBizTmp.getBizStatus(), globalMcNo);
                throw new BizException(RespCodeEnum.WRONG_TMP_BIZ_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_TMP_BIZ_STATUS_TO_SUBMIT_ERROR.getRespDesc());
            }

            /* 正常结束数据库事务 */
            dbsUtil.dbsEndTransaction(true);

        } else {
            /* 异常结束数据库事务 */
            rglog.error("查询营销活动信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 更新营销活动信息
     * 修改草稿流程使用
     *
     * @param editMoneyOffMcDetailRequest 减免类营销活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/4/2 00:13
     */
    private void updateAllDraftMcInfoByBank(DbsUtil dbsUtil, EditMoneyOffMcDetailRequest editMoneyOffMcDetailRequest) throws Exception {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();
        tmPlatBizTmp.setInstId(globalInstId);
        tmPlatBizTmp.setMcNo(globalMcNo);
        tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
        tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
        tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());

        /* 删错指定营销活动编号的所有草稿状态的数据数据 */
        deleteAllDraftMcInfoByBank(dbsUtil);
        /* 处理因机构变更导致需要删除的商户数据 */
        delMchntListByDelOrgList(dbsUtil, editMoneyOffMcDetailRequest.getOrgInfoList());

        TMMcMoneyOffInfo tmMcMoneyOffInfo = convertMcInfo(editMoneyOffMcDetailRequest.getMcInfoObj());
        deleteMoMcInfo(dbsUtil);
        deleteMcOrgInfo(dbsUtil);
        /* 保留商户数据，删除商圈数据*/
        //deleteMcMchntInfo(dbsUtil);
        deleteMcMchntAreat(dbsUtil, CommonConstant.ONE_COMMON_CONSTANT);


        deleteMcUserInfo(dbsUtil);
        deleteMcTimeInfo(dbsUtil);
        deleteMcMoRuleInfo(dbsUtil);
        deleteMcProductInfo(dbsUtil);
        insertAllMcInfoByBank(dbsUtil, editMoneyOffMcDetailRequest);
    }

    /**
     * 生成营销活动编号
     *
     * @param moneyOffMcInfoBean 减免类活动基本信息对象
     * @return java.lang.String
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 14:57
     */
    private String generateNewMcNo(MoneyOffMcInfoBean moneyOffMcInfoBean) throws Exception {

        // MC+2位营销活动类型+1位出资方+8位活动起始日期+8位活动截止日期+11位sequence
        MompSequenceMapper mompSequenceMapper = new MompSequenceMapperImpl();

        String mcNoSuffix = mompSequenceMapper.getMompNextMaNoSeq();

        return "MC" + moneyOffMcInfoBean.getMcType() + moneyOffMcInfoBean.getSponsor() + moneyOffMcInfoBean.getMcStartDate() + moneyOffMcInfoBean.getMcEndDate() + mcNoSuffix;
    }


    /**
     * 插入减免类营销活动基本信息
     *
     * @param dbsUtil        数据库操作工具类
     * @param mcMoneyOffInfo 减免类营销活动信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 16:35
     */
    private void insertMoMcInfo(DbsUtil dbsUtil, TMMcMoneyOffInfo mcMoneyOffInfo) throws Exception {

        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        int returnCode = mcDetailInfoMapper.insertSingleMoneyOffMcInfo(mcMoneyOffInfo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 将减免类营销活动基本信息插入临时表中
     *
     * @param dbsUtil      数据库操作工具类
     * @param tmPlatBizTmp 业务数据临时表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/22 15:39
     */
    private void insertTmpMoMcInfo(DbsUtil dbsUtil, TMPlatBizTmp tmPlatBizTmp) throws Exception {

        /* 数据入库 */
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.insertMcInfoByBank(tmPlatBizTmp);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 减免类营销活动信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param mcMoneyOffInfo 减免类营销活动信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @since 2020/5/22 11:49
     */
    private TMPlatBizTmp convertMoMcInfoToTmp(TMMcMoneyOffInfo mcMoneyOffInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(mcMoneyOffInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(mcMoneyOffInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_MO_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TABLE_NAME);
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMoMcInfoTmpBizData1(mcMoneyOffInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动机构信息表
     *
     * @param dbsUtil       数据库操作工具类
     * @param mcOrgInfoList 营销活动机构信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 16:38
     */
    private void insertMcOrgInfo(DbsUtil dbsUtil, List<TMMcOrgInfo> mcOrgInfoList) throws Exception {

        McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
        int returnCode = mcOrgInfoMapper.insertMcOrgInfoListByBank(mcOrgInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动机构信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 将营销活动机构信息插入临时表中
     *
     * @param dbsUtil          数据库操作工具类
     * @param tmPlatBizTmpList 业务数据临时表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/28 22:17
     */
    private void insertMultiMcDetialInfoByBank(DbsUtil dbsUtil, List<TMPlatBizTmp> tmPlatBizTmpList) throws Exception {

        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.insertMultiMcDetialInfoByBank(tmPlatBizTmpList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动机构信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动机构信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcOrgInfo 营销活动机构信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @since 2020/5/28 22:12
     */
    private TMPlatBizTmp convertMcOrgInfoToTmp(TMMcOrgInfo tmMcOrgInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcOrgInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcOrgInfo.getMcNo());
            /* 机构编号 */
            tmPlatBizTmp.setOrgId(tmMcOrgInfo.getOrgId());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_ORG_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_ORG_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcOrgInfoTmpBizData1(tmMcOrgInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动商户信息
     *
     * @param dbsUtil         数据库操作工具类
     * @param mcMchntInfoList 营销活动商户信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:05
     */
    private void insertMcMchntInfo(DbsUtil dbsUtil, List<TMMcMchntInfo> mcMchntInfoList) throws Exception {
        if (mcMchntInfoList != null && !mcMchntInfoList.isEmpty()) {
            rglog.info("编辑营销活动新增商户/商圈信息列表size<{}>", mcMchntInfoList.size());
            McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
            int returnCode = mcMchntInfoMapper.insertMcMchntInfoListByBank(mcMchntInfoList);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 异常结束数据库事务 */
                rglog.error("新增营销活动商户/商圈信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
            }
        } else {
            rglog.info("编辑营销活动新增商户/商圈信息列表无数据，MC_NO=<{}>", globalMcNo);
        }
    }

    /**
     * 营销活动商户信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcMchntInfo 营销活动商户信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @since 2020/5/28 22:26
     */
    private TMPlatBizTmp convertMcMchntInfoToTmp(TMMcMchntInfo tmMcMchntInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcMchntInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcMchntInfo.getMcNo());
            /* 商户编号 */
            tmPlatBizTmp.setMchntNo(tmMcMchntInfo.getMchntNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 新增商户标志 */
            tmMcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_OLD_FLAG);
            /* 退出标志 */
            tmMcMchntInfo.setExitFlag(CommonConstant.MC_NOT_EXIT_FLAG);
            /* 达标日期 */
            tmMcMchntInfo.setQualifiedDate(globalTxnDate);
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcMchntInfoTmpBizData1(tmMcMchntInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);
            /* 使用remark1字段存储商户范围 */
            tmPlatBizTmp.setRemark1(tmMcMchntInfo.getMchntType());

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动用户信息
     *
     * @param dbsUtil        数据库操作工具类
     * @param mcUserInfoList 营销活动用户信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:11
     */
    private void insertMcUserInfo(DbsUtil dbsUtil, List<TMMcUserInfo> mcUserInfoList) throws Exception {

        McUserInfoMapper mcUserInfoMapper = new McUserInfoMapperImpl();
        int returnCode = mcUserInfoMapper.insertMcUserInfoListByBank(mcUserInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动用户信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动用户信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcUserInfo 营销活动用户信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @since 2020/5/28 22:35
     */
    private TMPlatBizTmp convertMcUserInfoToTmp(TMMcUserInfo tmMcUserInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcUserInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcUserInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_USER_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_USER_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcUserInfoTmpBizData1(tmMcUserInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动时间信息
     *
     * @param dbsUtil        数据库操作工具类
     * @param mcTimeInfoList 营销活动时间信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:13
     */
    private void insertMcTimeInfo(DbsUtil dbsUtil, List<TMMcTimeInfo> mcTimeInfoList) throws Exception {

        McTimeInfoMapper mcTimeInfoMapper = new McTimeInfoMapperImpl();
        int returnCode = mcTimeInfoMapper.insertMcTimeInfoListByBank(mcTimeInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动时间信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动时间信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcTimeInfo TMMcTimeInfo
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @since 2020/5/28 22:47
     */
    private TMPlatBizTmp convertMcTimeInfoToTmp(TMMcTimeInfo tmMcTimeInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcTimeInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcTimeInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_TIME_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_TIME_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcTimeInfoTmpBizData1(tmMcTimeInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动减免类规则信息
     *
     * @param dbsUtil                数据库操作工具类
     * @param mcMoneyOffRuleInfoList 减免类营销活动规则表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:15
     */
    private void insertMcMoRuleInfo(DbsUtil dbsUtil, List<TMMcMoneyOffRuleInfo> mcMoneyOffRuleInfoList) throws Exception {

        McRuleInfoMapper mcRuleInfoMapper = new McRuleInfoMapperImpl();
        int returnCode = mcRuleInfoMapper.insertMoneyOffRuleInfoListByBank(mcMoneyOffRuleInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动减免类规则信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动规则信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcMoneyOffRuleInfo 减免类营销活动规则表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @since 2020/5/28 22:49
     */
    private TMPlatBizTmp convertMoMcRuleInfoToTmp(TMMcMoneyOffRuleInfo tmMcMoneyOffRuleInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcMoneyOffRuleInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcMoneyOffRuleInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_MO_RULE_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MO_RULE_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMoMcRuleInfoTmpBizData1(tmMcMoneyOffRuleInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动产品信息
     *
     * @param dbsUtil           数据库操作工具类
     * @param mcProductInfoList 营销活动产品信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:08
     */
    private void insertMcProductInfo(DbsUtil dbsUtil, List<TMMcProductInfo> mcProductInfoList) throws Exception {

        McProductInfoMapper mcProductInfoMapper = new McProductInfoMapperImpl();
        int returnCode = mcProductInfoMapper.insertMcProductInfoListByBank(mcProductInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动产品信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动产品信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcProductInfo 营销活动产品信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @since 2020/5/28 22:49
     */
    private TMPlatBizTmp convertMcProdInfoToTmp(TMMcProductInfo tmMcProductInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcProductInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcProductInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_PROD_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_PROD_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcProdInfoTmpBizData1(tmMcProductInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 删除减免类营销活动基本信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 16:35
     */
    private void deleteMoMcInfo(DbsUtil dbsUtil) throws Exception {

        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        int returnCode = mcDetailInfoMapper.deleteMoneyOffMcInfo(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动机构信息表
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 16:38
     */
    private void deleteMcOrgInfo(DbsUtil dbsUtil) throws Exception {

        McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
        int returnCode = mcOrgInfoMapper.deleteMcOrgInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动机构信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动商户信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:05
     */
    private void deleteMcMchntInfo(DbsUtil dbsUtil) throws Exception {

        McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
        int returnCode = mcMchntInfoMapper.deleteMcMchntInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动商户信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动用户信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:11
     */
    private void deleteMcUserInfo(DbsUtil dbsUtil) throws Exception {

        McUserInfoMapper mcUserInfoMapper = new McUserInfoMapperImpl();
        int returnCode = mcUserInfoMapper.deleteMcUserInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动用户信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动时间信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:13
     */
    private void deleteMcTimeInfo(DbsUtil dbsUtil) throws Exception {

        McTimeInfoMapper mcTimeInfoMapper = new McTimeInfoMapperImpl();
        int returnCode = mcTimeInfoMapper.deleteMcTimeInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动时间信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动减免类规则信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:15
     */
    private void deleteMcMoRuleInfo(DbsUtil dbsUtil) throws Exception {

        McRuleInfoMapper mcRuleInfoMapper = new McRuleInfoMapperImpl();
        int returnCode = mcRuleInfoMapper.deleteMoneyOffRuleInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动减免类规则信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动产品信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:08
     */
    private void deleteMcProductInfo(DbsUtil dbsUtil) throws Exception {

        McProductInfoMapper mcProductInfoMapper = new McProductInfoMapperImpl();
        int returnCode = mcProductInfoMapper.deleteMcProductInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动产品信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除指定营销活动临时表数据
     * 保留商户临时表数据
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/28 23:12
     */
    private void deleteAllDraftMcInfoByBank(DbsUtil dbsUtil) throws Exception {
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        rglog.info("法人机构<{}>的营销活动<{}>删除临时表数据，仅保留商户信息");
        int returnCode = platBizTmpMapper.deleteTmpMcDataRetainMchntListByMcNo(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除草稿状态营销活动临时表数据失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 获取商户上月日均存款达标商户信息
     *
     * @param editMoneyOffMcDetailRequest 减免类营销活动信息编辑接口请求对象
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo> 营销活动商户信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020-06-29 01:17
     */
    private List<TMMcMchntInfo> fetchMchntInfoWithDeposit(EditMoneyOffMcDetailRequest editMoneyOffMcDetailRequest) throws Exception {

        List<TMMcMchntInfo> tmMcMchntInfoList = new ArrayList<>();

        BigDecimal amtFloor;
        BigDecimal amtCelling;
        if (!StringUtil.isNullorEmpty(editMoneyOffMcDetailRequest.getMcInfoObj().getAmtLimitFloor()) && !StringUtil.isNullorEmpty(editMoneyOffMcDetailRequest.getMcInfoObj().getAmtLimitCelling())) {
            amtFloor = new BigDecimal(editMoneyOffMcDetailRequest.getMcInfoObj().getAmtLimitFloor()).setScale(CommonConstant.DECIMAL_SCALE_TWO, RoundingMode.HALF_UP);
            amtCelling = new BigDecimal(editMoneyOffMcDetailRequest.getMcInfoObj().getAmtLimitCelling()).setScale(CommonConstant.DECIMAL_SCALE_TWO, RoundingMode.HALF_UP);
        } else {
            rglog.error("法人机构<{}>的营销活动<{}>未指定上月日均存款达标范围!", globalInstId, globalMcNo);
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        String sponsor = editMoneyOffMcDetailRequest.getMcInfoObj().getSponsor();

        /* 获取参加营销活动的机构下的所有商户信息 */
        List<McOrgInfoBean> mcOrgInfoBeanList = editMoneyOffMcDetailRequest.getOrgInfoList();

        List<TBMchntBaseInfo> tbMchntBaseInfoList = new ArrayList<>();
        MchntInfoMapper mchntInfoMapper = new MchntInfoMapperImpl();
        for (McOrgInfoBean mcOrgInfoBean : mcOrgInfoBeanList) {

            List<TBMchntBaseInfo> tbMchntBaseInfoList1 = mchntInfoMapper.selectMchntBaseInfoListBySignInstId(globalInstId, mcOrgInfoBean.getOrgId());
            if (null == tbMchntBaseInfoList1 || tbMchntBaseInfoList1.isEmpty()) {
                rglog.info("法人机构<{}>的机构<{}>未查询到签约商户信息!", globalInstId, mcOrgInfoBean.getOrgId());
                continue;
            }

            tbMchntBaseInfoList.addAll(tbMchntBaseInfoList1);
        }

        if (tbMchntBaseInfoList.isEmpty()) {
            rglog.info("法人机构<{}>的营销活动<{}>的所有机构未匹配到签约商户信息!", globalInstId, globalMcNo);
            return null;
        }

        String lastMonth = DateUtil.getBaseDateOffsetMonth(globalTxnDate, CommonConstant.MINUS_ONE).substring(0, 6);

        /* 逐个商户判断是否满足达标条件 */
        TMMchntMonthDepositMapper tmMchntMonthDepositMapper = new TMMchntMonthDepositMapperImpl();
        for (TBMchntBaseInfo tbMchntBaseInfo : tbMchntBaseInfoList) {
            TMMchntMonthDeposit tmMchntMonthDeposit = tmMchntMonthDepositMapper.selectLastMonthDepositInfo(globalInstId, tbMchntBaseInfo.getMchntNo(), lastMonth);
            if (null == tmMchntMonthDeposit) {
                rglog.info("未查询到法人机构<{}>的商户<{}>在<{}>的上月日均余额数据,该商户不可参加营销活动<{}>", globalInstId, tbMchntBaseInfo.getMchntNo(), lastMonth);
                continue;
            }

            /* 判断商户上月日均余额是否在范围内 */
            BigDecimal deposit = new BigDecimal(tmMchntMonthDeposit.getMchntDeposit()).setScale(CommonConstant.DECIMAL_SCALE_TWO, RoundingMode.HALF_UP);

            if (CommonConstant.ZERO <= deposit.compareTo(amtFloor) && CommonConstant.ZERO >= deposit.compareTo(amtCelling)) {

                TMMcMchntInfo tmMcMchntInfo = new TMMcMchntInfo();
                tmMcMchntInfo.setInstId(globalInstId);
                tmMcMchntInfo.setMcNo(globalMcNo);
                tmMcMchntInfo.setMchntNo(tbMchntBaseInfo.getMchntNo());
                tmMcMchntInfo.setMchntType(CommonConstant.MCHNT_RANGE_TYPE_MCHNT);
                tmMcMchntInfo.setMchntName(tbMchntBaseInfo.getMchntName());
                tmMcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_OLD_FLAG);
                if (CommonConstant.SPONSOR_MIXED.equals(sponsor)) {
                    tmMcMchntInfo.setExitFlag(CommonConstant.MC_EXIT_FLAG);
                } else {
                    tmMcMchntInfo.setExitFlag(CommonConstant.MC_NOT_EXIT_FLAG);
                }
                tmMcMchntInfo.setQualifiedDate(globalTxnDate);
                tmMcMchntInfo.setOprId(globalOprId);
                tmMcMchntInfo.setCreateTime(globalTimeStamp);

                tmMcMchntInfoList.add(tmMcMchntInfo);
            }
        }

        if (tmMcMchntInfoList.isEmpty()) {
            return null;
        } else {
            return tmMcMchntInfoList;
        }
    }

    /**
     * 获取商户上月日均交易额达标商户信息
     *
     * @param editMoneyOffMcDetailRequest 减免类营销活动信息编辑接口请求对象
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo> 营销活动商户信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020-06-29 01:19
     */
    private List<TMMcMchntInfo> fetchMchntInfoWithTxnAmt(EditMoneyOffMcDetailRequest editMoneyOffMcDetailRequest) throws Exception {

        List<TMMcMchntInfo> tmMcMchntInfoList = new ArrayList<>();

        BigDecimal amtFloor;
        BigDecimal amtCelling;
        if (!StringUtil.isNullorEmpty(editMoneyOffMcDetailRequest.getMcInfoObj().getAmtLimitFloor()) && !StringUtil.isNullorEmpty(editMoneyOffMcDetailRequest.getMcInfoObj().getAmtLimitCelling())) {
            amtFloor = new BigDecimal(editMoneyOffMcDetailRequest.getMcInfoObj().getAmtLimitFloor()).setScale(CommonConstant.DECIMAL_SCALE_TWO, RoundingMode.HALF_UP);
            amtCelling = new BigDecimal(editMoneyOffMcDetailRequest.getMcInfoObj().getAmtLimitCelling()).setScale(CommonConstant.DECIMAL_SCALE_TWO, RoundingMode.HALF_UP);
        } else {
            rglog.error("法人机构<{}>的营销活动<{}>未指定上月日均交易额达标范围!", globalInstId, globalMcNo);
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        String sponsor = editMoneyOffMcDetailRequest.getMcInfoObj().getSponsor();

        /* 获取参加营销活动的机构下的所有商户信息 */
        List<McOrgInfoBean> mcOrgInfoBeanList = editMoneyOffMcDetailRequest.getOrgInfoList();

        List<TBMchntBaseInfo> tbMchntBaseInfoList = new ArrayList<>();
        MchntInfoMapper mchntInfoMapper = new MchntInfoMapperImpl();
        for (McOrgInfoBean mcOrgInfoBean : mcOrgInfoBeanList) {

            List<TBMchntBaseInfo> tbMchntBaseInfoList1 = mchntInfoMapper.selectMchntBaseInfoListBySignInstId(globalInstId, mcOrgInfoBean.getOrgId());
            if (null == tbMchntBaseInfoList1 || tbMchntBaseInfoList1.isEmpty()) {
                rglog.info("法人机构<{}>的机构<{}>未查询到签约商户信息!", globalInstId, mcOrgInfoBean.getOrgId());
                continue;
            }

            tbMchntBaseInfoList.addAll(tbMchntBaseInfoList1);
        }

        if (tbMchntBaseInfoList.isEmpty()) {
            rglog.info("法人机构<{}>的营销活动<{}>的所有机构未匹配到签约商户信息!", globalInstId, globalMcNo);
            return null;
        }

        String lastMonth = DateUtil.getBaseDateOffsetMonth(globalTxnDate, CommonConstant.MINUS_ONE).substring(0, 6);

        /* 逐个商户判断是否满足达标条件 */
        TCTxnStatisMapper tcTxnStatisMapper = new TCTxnStatisMapperImpl();
        for (TBMchntBaseInfo tbMchntBaseInfo : tbMchntBaseInfoList) {
            TCTxnStatis tcTxnStatis = tcTxnStatisMapper.selectMchntLastMonthTxnStatisticsByPrimaryKey(globalInstId, lastMonth, tbMchntBaseInfo.getMchntNo());
            if (null == tcTxnStatis) {
                rglog.info("未查询到法人机构<{}>的商户<{}>在<{}>的上月日均余额数据,该商户不可参加营销活动<{}>", globalInstId, tbMchntBaseInfo.getMchntNo(), lastMonth);
                continue;
            }

            /* 判断商户上月日交易额是否在范围内 */
            BigDecimal txnAmt = new BigDecimal(tcTxnStatis.getTotalTransAmt()).divide(new BigDecimal("30"), CommonConstant.DECIMAL_SCALE_TWO, RoundingMode.HALF_UP);

            if (CommonConstant.ZERO <= txnAmt.compareTo(amtFloor) && CommonConstant.ZERO >= txnAmt.compareTo(amtCelling)) {

                TMMcMchntInfo tmMcMchntInfo = new TMMcMchntInfo();
                tmMcMchntInfo.setInstId(globalInstId);
                tmMcMchntInfo.setMcNo(globalMcNo);
                tmMcMchntInfo.setMchntNo(tbMchntBaseInfo.getMchntNo());
                tmMcMchntInfo.setMchntType(CommonConstant.MCHNT_RANGE_TYPE_MCHNT);
                tmMcMchntInfo.setMchntName(tbMchntBaseInfo.getMchntName());
                tmMcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_OLD_FLAG);
                if (CommonConstant.SPONSOR_MIXED.equals(sponsor)) {
                    tmMcMchntInfo.setExitFlag(CommonConstant.MC_EXIT_FLAG);
                } else {
                    tmMcMchntInfo.setExitFlag(CommonConstant.MC_NOT_EXIT_FLAG);
                }
                tmMcMchntInfo.setQualifiedDate(globalTxnDate);
                tmMcMchntInfo.setOprId(globalOprId);
                tmMcMchntInfo.setCreateTime(globalTimeStamp);

                tmMcMchntInfoList.add(tmMcMchntInfo);
            }
        }

        if (tmMcMchntInfoList.isEmpty()) {
            return null;
        } else {
            return tmMcMchntInfoList;
        }

    }

    /**
     * 校验接口上送的商户信息和机构信息是否匹配
     *
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/7/14 14:00
     */
    private void checkMchntAndOrgInfo(EditMoneyOffMcDetailRequest editMoneyOffMcDetailRequest) throws Exception {

        traceNo = editMoneyOffMcDetailRequest.getHeader().getTraceNo();

        List<McOrgInfoBean> orgInfoList = editMoneyOffMcDetailRequest.getOrgInfoList();
        List<McMchntInfoBean> mchntInfoList = editMoneyOffMcDetailRequest.getMchntInfoList();

        if (null == orgInfoList || orgInfoList.isEmpty()) {
            rglog.error("交易流水号：<{}>, 接口请求上送的营销活动机构信息为空", traceNo);
            throw new BizException(RespCodeEnum.GET_MC_ORG_INFO_ERROR.getRespCode(), RespCodeEnum.GET_MC_ORG_INFO_ERROR.getRespDesc());
        }
        if (merFileFlag) {
            String merFilePath = editMoneyOffMcDetailRequest.getMrctFilePath();
            rglog.info("交易流水号：<{}>, 接口请求上送的营销活动商户文件路径：<{}>，暂不校验商户及机构是否匹配，流程继续...", traceNo, merFilePath);
        } else {
            if (null == mchntInfoList || mchntInfoList.isEmpty()) {
                rglog.info("交易流水号：<{}>, 接口请求上送的营销活动商户信息为空，不校验商户及机构是否匹配，流程继续...", traceNo);
            } else {
                rglog.info("交易流水号：<{}>, 接口请求上送的营销活动商户信息不为空size=<{}>，校验商户及机构是否匹配，流程继续...", traceNo, mchntInfoList.size());
                List<String> mchntRealOrgList = new ArrayList<>();
                List<String> requestOrgList = new ArrayList<>();
                String mchntType, mchntNo;
                MchntInfoMapper mchntInfoMapper = new MchntInfoMapperImpl();
                TBTradeAreaInfoMapper tbTradeAreaInfoMapperImpl = new TBTradeAreaInfoMapperImpl();

                int maxSize = mchntInfoList.size();
                for (int i = 0; i < maxSize; i++) {
                    McMchntInfoBean mcMchntInfoBean = mchntInfoList.get(i);
                    //商户类型
                    mchntType = mcMchntInfoBean.getMchntType();
                    //商户范围号
                    mchntNo = mcMchntInfoBean.getMchntNo();

                    if (CommonConstant.ZERO_COMMON_CONSTANT.equals(mchntType)) {
                        rglog.info("交易流水号：<{}>, 查询商户<{}>信息开始...", traceNo, mchntNo);

                        String oprType = mcMchntInfoBean.getOprType();
                        /** 增加操作类型节点非空校验 */
                        if (StringUtil.isNullorEmpty(oprType)) {
                            rglog.error("交易流水号：<{}>, 商户列表数据<{}>操作类型<{}>节点未上送！", traceNo, mchntNo, oprType);
                            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc() + ",商户号" + mchntNo);
                        }

                        //查询商户基本信息
                        TBMchntBaseInfo tbMchntBaseInfo = mchntInfoMapper.selectMchntBaseInfoByMchntNo(globalInstId, mchntNo);
                        if (null == tbMchntBaseInfo) {
                            rglog.error("交易流水号：<{}>, 商户<{}>信息查询异常！", traceNo, mchntNo);
                            throw new BizException(RespCodeEnum.GET_MCHNT_BASE_INFO_ERROR_BY_FORMAL.getRespCode(), RespCodeEnum.GET_MCHNT_BASE_INFO_ERROR_BY_FORMAL.getRespDesc() + ",商户号" + mchntNo);
                        }

                        /** 存量营销活动筛选上传的商户列表，去除oprType=I已存在的商户、去除oprType=D不存在的商户 */
                        if (!StringUtil.isNullorEmpty(globalMcNo)) {
                            rglog.info("校验接口上送的新增/删除商户列表报文是否冗余");
                            McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
                            TMMcMchntInfo mchntInfo = mcMchntInfoMapper.selectTMMcMchntInfoByPrimaryKey(globalInstId, globalMcNo, mchntNo);
                            if (OprTypeEnum.INSERT.getOprTypeCode().equals(oprType)) {
                                if (null != mchntInfo) {
                                    rglog.info("交易流水号：<{}>, 商户列表数据<{}>新增操作校验不通过，该商户已存在，跳过该商户继续流程！", traceNo, mchntNo);
                                    mchntInfoList.remove(mcMchntInfoBean);
                                    maxSize--;
                                    i--;
                                    continue;
                                }
                            } else if (OprTypeEnum.DELETE.getOprTypeCode().equals(oprType)) {
                                if (null == mchntInfo) {
                                    rglog.info("交易流水号：<{}>, 商户列表数据<{}>删除操作校验不通过，该商户不存在无法删除，跳过该商户继续流程！", traceNo, mchntNo);
                                    mchntInfoList.remove(mcMchntInfoBean);
                                    maxSize--;
                                    i--;
                                    continue;
                                }
                            } else {
                                rglog.error("交易流水号：<{}>, 商户列表数据<{}>操作类型<{}>节点值上送错误！", traceNo, mchntNo, oprType);
                                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc() + ",商户号" + mchntNo + "操作类型节点值上送错误");
                            }
                        }
                        mchntRealOrgList.add(tbMchntBaseInfo.getSignInstId());

                    } else if (CommonConstant.ONE_COMMON_CONSTANT.equals(mchntType)) {
                        rglog.info("交易流水号：<{}>, 查询商圈<{}>信息开始...", traceNo, mchntNo);
                        //查询商圈基本信息
                        TBTradeAreatInfo TBTradeAreatInfo = tbTradeAreaInfoMapperImpl.selectTradeAreaInfoByTradeAreaCode(globalInstId, mchntNo);
                        if (null == TBTradeAreatInfo) {
                            rglog.error("交易流水号：<{}>, 商圈<{}>信息查询异常！", traceNo, mchntNo);
                            throw new BizException(RespCodeEnum.GET_TRADE_AREA_INFO_ERROR.getRespCode(), RespCodeEnum.GET_TRADE_AREA_INFO_ERROR.getRespDesc());
                        }
                        mchntRealOrgList.add(TBTradeAreatInfo.getBelongInstId());
                    } else {
                        rglog.error("交易流水号：<{}>, 接口请求上送的商户类型错误...", traceNo);
                        throw new BizException(RespCodeEnum.WRONG_MC_MCHNTTYPE.getRespCode(), RespCodeEnum.WRONG_MC_MCHNTTYPE.getRespDesc());
                    }
                }

                rglog.info("交易流水号：<{}>, 接口请求上送的营销活动商户信息不为空size=<{}>，校验商户及机构是否匹配完成，筛除不符合商户数据后size=<{}>", traceNo, mchntInfoList.size());

                //对请求上送的商户所属的机构进行去重处理
                mchntRealOrgList = mchntRealOrgList.stream().distinct().collect(Collectors.toList());

                //处理接口请求上送的机构信息
                List<String> requestOrgIdList = orgInfoList.stream().map(item -> item.getOrgId()).collect(Collectors.toList());
                //对请求上送的机构进行去重处理
                requestOrgIdList = requestOrgIdList.stream().distinct().collect(Collectors.toList());

                //比较通过接口上送的机构号是否包含通过商户筛选出的机构号
                if (requestOrgIdList.containsAll(mchntRealOrgList)) {
                    rglog.info("交易流水号：<{}>, 接口上送的机构信息与商户所属机构信息校验通过！", traceNo);
                } else {
                    rglog.error("交易流水号：<{}>, 接口上送的机构信息与商户所属机构信息失败！", traceNo);
                    throw new BizException(RespCodeEnum.CHECK_MCHNTREALORG_REQUESTORG_FAIL.getRespCode(), RespCodeEnum.CHECK_MCHNTREALORG_REQUESTORG_FAIL.getRespDesc());
                }
            }
        }

        OrganizationMapper organizationMapper = new OrganizationMapperImpl();
        /* 接口上送的机构信息中不包含当前机构所属的上级机构，所以需要把上属机构补充道机构信息表中*/
        //需要从接口上送的机构信息中添加的上级机构
        List<McOrgInfoBean> addOrgIdList = new ArrayList<>();
        //最终机构信息（补充完上级机构后的机构列表）
        List<McOrgInfoBean> requestResultOrgList = editMoneyOffMcDetailRequest.getOrgInfoList();

        String queryOrgId = editMoneyOffMcDetailRequest.getQueryOrgId();
        //查询当前登录用户的所属机构信息
        Organization queryOrgInfo = organizationMapper.selectOrganization(globalInstId, queryOrgId);
        //当前登录用户所属机构的最大深度
        int orgLevealDepth = 6;
        Boolean superOrgFlag = false;
        while (orgLevealDepth > 0) {
            if (null != queryOrgInfo) {
                if (superOrgFlag) {
                    McOrgInfoBean mcOrgInfoBean = new McOrgInfoBean();
                    mcOrgInfoBean.setOrgHierarchy(queryOrgInfo.getOrgLevel());
                    mcOrgInfoBean.setOrgId(queryOrgInfo.getOrgCode());
                    mcOrgInfoBean.setOrgName(queryOrgInfo.getOrgName());
                    mcOrgInfoBean.setOprType(CommonConstant.DEFAULT_OPR_ID);
                    addOrgIdList.add(mcOrgInfoBean);
                }
                String superOrgId = queryOrgInfo.getSuperOrgCode();
                String orgLevel = queryOrgInfo.getOrgLevel();
                rglog.info("交易流水号：<{}>,当前机构机构编码<{}>,上级机构编码<{}>,机构编码级别<{}>", traceNo, queryOrgInfo.getOrgCode(), superOrgId, orgLevel);

                if (null != superOrgId && !"00".equals(orgLevel)) {
                    rglog.info("交易流水号：<{}>,接口请求上送的机构信息中需要添加 <{}>!", traceNo, superOrgId);
                    queryOrgInfo = organizationMapper.selectOrganization(globalInstId, superOrgId);
                    superOrgFlag = true;
                } else {
                    break;
                }
                orgLevealDepth--;
            } else {
                rglog.error("交易流水号：<{}>, 机构<{}>机构信息查询失败！", traceNo, addOrgIdList.size(), queryOrgId);
                throw new BizException(RespCodeEnum.NO_ORG_INFO_ERROR.getRespCode(), RespCodeEnum.NO_ORG_INFO_ERROR.getRespDesc());
            }
        }

        if (null != addOrgIdList && !addOrgIdList.isEmpty()) {
            rglog.info("交易流水号：<{}>, 接口上送的机构机构信息中有需要添加<{}>个上级机构信息", traceNo, addOrgIdList.size());
            requestResultOrgList.addAll(addOrgIdList);
            editMoneyOffMcDetailRequest.setOrgInfoList(requestResultOrgList);
        } else {
            rglog.info("交易流水号：<{}>, 接口上送的机构机构信息中不需要添加上级机构信息（当前用户所属机构已经为总行级别）", traceNo, addOrgIdList.size());
        }
    }

    /**
     * 营销活动商户信息数据库实体类和接口实体类数据转换(进行中新增商户)
     *
     * @param mcMchntInfoBean 营销活动商户信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcMchntInfo 营销活动商户信息表
     * @author JL PANG
     * @since 2020/7/20
     */
    private TMMcMchntInfo convertMcMchntInfos(McMchntInfoBean mcMchntInfoBean) {
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        try {
            /* 法人机构号 */
            mcMchntInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcMchntInfo.setMcNo(globalMcNo);
            /* 商户范围类型 */
            mcMchntInfo.setMchntType(mcMchntInfoBean.getMchntType());
            /* 商户范围号 */
            mcMchntInfo.setMchntNo(mcMchntInfoBean.getMchntNo());
            /* 商户范围名称 */
            mcMchntInfo.setMchntName(mcMchntInfoBean.getMchntName());
            /* 新增商户标志 */
            mcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_NEW_FLAG);
            /* 退出标志 */
            mcMchntInfo.setExitFlag(CommonConstant.MC_EXIT_FLAG);
            /* 达标日期 */
            mcMchntInfo.setQualifiedDate(globalTxnDate);
            /* 创建人 */
            mcMchntInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcMchntInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcMchntInfo;
    }

    /**
     * 营销活动商户信息表数据转换
     * 正式表数据转换为临时表数据(进行中新增商户)
     *
     * @param tmMcMchntInfo 营销活动商户信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author JL Pang
     * @since 2020/5/28 22:26
     */
    private TMPlatBizTmp convertMcMchntInfoToTmps(TMMcMchntInfo tmMcMchntInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcMchntInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcMchntInfo.getMcNo());
            //商户名称
            tmPlatBizTmp.setMchntName(tmMcMchntInfo.getMchntName());
            /* 商户编号 */
            tmPlatBizTmp.setMchntNo(tmMcMchntInfo.getMchntNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 新增商户标志 */
            tmMcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_OLD_FLAG);
            /* 退出标志 */
            tmMcMchntInfo.setExitFlag(CommonConstant.MC_NOT_EXIT_FLAG);
            /* 达标日期 */
            tmMcMchntInfo.setQualifiedDate(globalTxnDate);
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcMchntInfoTmpBizData1(tmMcMchntInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);
            tmPlatBizTmp.setRemark1(tmMcMchntInfo.getMchntType());

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 检查 上送 营销活动信息 金额字段不能为负数
     *
     * @param moneyOffMcInfoBean
     * @author ls
     * @date 2020/10/21
     */
    private void checkMcInfoObjFieldHasNegativeNumber(MoneyOffMcInfoBean moneyOffMcInfoBean) {
        /* 参与次数限制 */
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getRestriction()) && new BigDecimal(moneyOffMcInfoBean.getRestriction()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 限制金额下限 */
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getAmtLimitFloor()) && new BigDecimal(moneyOffMcInfoBean.getAmtLimitFloor()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 限制金额上限 */
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getAmtLimitCelling()) && new BigDecimal(moneyOffMcInfoBean.getAmtLimitCelling()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 预算 */
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getBudget()) && new BigDecimal(moneyOffMcInfoBean.getBudget()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /*银行出资预算	bankBudget*/
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getBankBudget()) && new BigDecimal(moneyOffMcInfoBean.getBankBudget()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 预期参与商户数量 */
        if (!StringUtil.isNullorEmpty(moneyOffMcInfoBean.getExpectMchntQty()) && new BigDecimal(moneyOffMcInfoBean.getExpectMchntQty()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }

    }

    /**
     * 检查 上送 销活动规则信息数据 金额字段不能为负数
     *
     * @param moneyOffRuleInfoBean
     * @author ls
     * @date 2020/10/21
     */
    private void checkRuleInfoFieldHasNegativeNumber(MoneyOffRuleInfoBean moneyOffRuleInfoBean) {
        // 检查上传字段 不能为负数
        /* 活动门槛 */
        if (!StringUtil.isNullorEmpty(moneyOffRuleInfoBean.getCriteria()) && new BigDecimal(moneyOffRuleInfoBean.getCriteria()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 优惠力度下限 */
        if (!StringUtil.isNullorEmpty(moneyOffRuleInfoBean.getDiscountFloor()) && new BigDecimal(moneyOffRuleInfoBean.getDiscountFloor()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 优惠力度上限 */
        if (!StringUtil.isNullorEmpty(moneyOffRuleInfoBean.getDiscountCelling()) && new BigDecimal(moneyOffRuleInfoBean.getDiscountCelling()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 总优惠数量 */
        if (!StringUtil.isNullorEmpty(moneyOffRuleInfoBean.getDiscountQuantity()) && new BigDecimal(moneyOffRuleInfoBean.getDiscountQuantity()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 单次优惠限制 */
        if (!StringUtil.isNullorEmpty(moneyOffRuleInfoBean.getDiscountLimit()) && new BigDecimal(moneyOffRuleInfoBean.getDiscountLimit()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 优惠总预算 */
        if (!StringUtil.isNullorEmpty(moneyOffRuleInfoBean.getBudget()) && new BigDecimal(moneyOffRuleInfoBean.getBudget()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 单日消耗预算 */
        if (!StringUtil.isNullorEmpty(moneyOffRuleInfoBean.getBudgetDayLimit()) && new BigDecimal(moneyOffRuleInfoBean.getBudgetDayLimit()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }

    }

    /**
     * 新增商户定时任务
     *
     * @param mrctFilePath 文件路径
     * @throws Exception
     * @author liujinan
     * @date 2021/06/07
     */
    private void insertMcTaskInfoForMerFile(DbsUtil dbsUtil, String mrctFilePath) throws Exception {

        McTaskFlowMapper taskFlowMapper = new McTaskFlowMapperImpl();
        TMMcTaskFlow flow = new TMMcTaskFlow();
        globalFlowNo = DateUtil.getCurrentDateTime("yyyyMMddHHmmssSSS") + RandomUtil.getRandomInt();
        /* 存储业务数据 */
        JSONObject bizDate = new JSONObject();
        bizDate.put("auditStatus", flowAuditStatus);
        bizDate.put("tmpAuditStatus", flowTmpAuditStatus);
        rglog.info("交易流水号：<{}>,任务流水号<{}>,新增任务流水,备份原营销活动审批状态<{}>", traceNo, globalFlowNo, bizDate.toString());
        flow.setFlowNo(globalFlowNo);
        flow.setInstId(globalInstId);
        flow.setMcNo(globalMcNo);
        flow.setBizTypeCd("");
        flow.setBizTypeParamData(bizDate.toJSONString());
        flow.setCreateTm(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        flow.setTaskSts("00");
        flow.setFilePath(mrctFilePath);
        flow.setTxnDt(DateUtil.getCurrentDate());
        flow.setTxnTm(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        flow.setOprId(globalOprId);
        flow.setRmrk1(traceNo);

        int returnCode = taskFlowMapper.insertMcTaskFlow(flow);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增活动上传商户文件定时任务失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }

    }

    /**
     * 修改任务表业务数据
     *
     * @param dbsUtil
     * @param instId  成员行编号
     * @param mcNo    活动编号
     * @param flowNo  任务流水号
     * @param bizDate 业务数据
     * @throws Exception
     * @author liujinan
     * @date 2021/06/07
     */
    private void updateMcTaskInfoBizDate(DbsUtil dbsUtil, String instId, String mcNo, String flowNo, String bizDate) throws Exception {

        McTaskFlowMapper taskFlowMapper = new McTaskFlowMapperImpl();
        int returnCode = taskFlowMapper.updateMcTaskFlowBizDate(instId, mcNo, flowNo, bizDate);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("更新商户文件定时任务业务数据失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
        rglog.info("更新商户文件定时任务业务数据，备份业务数据状态");
    }

    /**
     * 临时表中将营销活动指定商户信息删除
     *
     * @param dbsUtil          数据库操作工具类
     * @param tmPlatBizTmpList 业务数据临时表
     * @throws Exception 异常信息
     * @author liujinan
     * @since 2020/5/28 22:17
     */
    private void deleteMultiMcDetialInfoByBank(DbsUtil dbsUtil, List<TMPlatBizTmp> tmPlatBizTmpList) throws Exception {

        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.deleteMultiMcMchntListByBank(tmPlatBizTmpList);
        //兼容批量未新增临时表问题
        if (Database.DBS_SUCCESS != returnCode && Database.DBS_NOT_FOUND != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动机构信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动指定商户信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author liujinan
     * @since 2020/4/12 16:05
     */
    private void deleteMcMchntInfoList(DbsUtil dbsUtil, List<TMMcMchntInfo> mcMchntInfoList) throws Exception {
        if (!mcMchntInfoList.isEmpty()) {
            rglog.info("编辑营销活动删除商户信息列表size<{}>", mcMchntInfoList.size());
            McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
            int returnCode = mcMchntInfoMapper.deleteMcMchntInfoList(globalInstId, globalMcNo, mcMchntInfoList);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 异常结束数据库事务 */
                rglog.error("删除营销活动商户信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
            }
        } else {
            rglog.info("编辑营销活动删除商户信息列表无数据，MC_NO=<{}>", globalMcNo);
        }
    }

    /**
     * 删除营销活动商户/商圈信息
     *
     * @param dbsUtil
     * @param mchntType 商户类型0商户1商圈
     * @throws Exception
     * @author liujinan
     * @since 2020/6/24 16:05
     */
    private void deleteMcMchntAreat(DbsUtil dbsUtil, String mchntType) throws Exception {
        McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
        int returnCode = mcMchntInfoMapper.deleteMchntInfoByType(globalInstId, globalMcNo, mchntType);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动商户/商圈信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>, MCHNT_TYPE=<{}>", returnCode, globalInstId, globalMcNo, mchntType);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 处理因机构变更导致需要删除的商户数据
     *
     * @param dbsUtil
     * @param orgInfoList 上传的机构列表信息
     * @throws Exception
     * @author liujinan
     * @since 2020/6/24 16:05
     */
    private void delMchntListByDelOrgList(DbsUtil dbsUtil, List<McOrgInfoBean> orgInfoList) throws Exception {
        List<String> delMchntNoList = new ArrayList<>();
        /* 查询营销活动原机构列表 */
        List<TMMcOrgInfo> newOrgInfoList = orgInfoList.stream().map(this::convertMcOrgInfo).collect(Collectors.toList());

        /* 获取上送机构列表、活动原机构列表 */
        McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
        List<TMMcOrgInfo> oldOrgInfoList = mcOrgInfoMapper.selectMcOrgInfoList(globalInstId, globalMcNo);

        List<String> newOrgs = newOrgInfoList.stream().map(item -> item.getOrgId()).collect(Collectors.toList());
        List<String> hisOrgs = oldOrgInfoList.stream().map(item -> item.getOrgId()).collect(Collectors.toList());
        rglog.info("机构变更-商户信息处理流程，本次上传机构列表size:<{}>,商户:<{}>", newOrgs.size(), newOrgs.toString());
        rglog.info("机构变更-商户信息处理流程，原活动机构列表size:<{}>,商户:<{}>", hisOrgs.size(), hisOrgs.toString());
        for (String orgId : newOrgs) {
            if (hisOrgs.contains(orgId)) {
                hisOrgs.remove(orgId);
            }
        }
        rglog.info("机构变更-商户信息处理流程，排查本次机构变更数据，待删除的机构列表size:<{}>,商户:<{}>", hisOrgs.size(), hisOrgs.toString());
        if (!hisOrgs.isEmpty()) {
            rglog.info("机构变更-商户信息处理流程，查询营销活动存量商户列表信息");
            List<Object> mcMchntInfoList = getAllMcMchntListInfo();
            if (mcMchntInfoList != null && !mcMchntInfoList.isEmpty()) {
                List<McMchntInfoBean> mcMchntInfoBeanList = mcMchntInfoList.stream().map(this::convertMcMchntInfo).collect(Collectors.toList());
                List<String> mchntNoList = mcMchntInfoBeanList.stream().map(item -> item.getMchntNo()).collect(Collectors.toList());
                rglog.info("机构变更-商户信息处理流程，查询营销活动存量商户列表信息:<{}>", mchntNoList.toString());

                rglog.info("机构变更-商户信息处理流程，存在删除的机构列表，开始排查该机构下是否存在参加活动的商户");
                MchntInfoMapper mchntInfoMapper = new MchntInfoMapperImpl();
                List<TBMchntBaseInfo> mchntNoForOrgList = new ArrayList<>();
                for (String signInstId : hisOrgs) {
                    //查询该机构下所有的商户列表
                    List<TBMchntBaseInfo> mchntInfoList = mchntInfoMapper.selectMchntBaseInfoListBySignInstId(globalInstId, signInstId);
                    mchntNoForOrgList.addAll(mchntInfoList);
                }
                if (!mchntNoList.isEmpty() && !mchntNoForOrgList.isEmpty()) {
                    List<String> mchntNoListForDelOrgs = mchntNoForOrgList.stream().map(item -> item.getMchntNo()).collect(Collectors.toList());
                    for (String mchntNo : mchntNoList) {
                        if (mchntNoListForDelOrgs.contains(mchntNo)) {
                            delMchntNoList.add(mchntNo);
                        }
                    }
                    rglog.info("机构变更-商户信息处理流程，待删除机构列表下属商户列表size:<{}>,商户:<{}>", delMchntNoList.size(), delMchntNoList.toString());
                }
            }
        }
        if (!delMchntNoList.isEmpty()) {
            List<TMMcMchntInfo> delOrgsMchntInfoList = delMchntNoList.stream().map(this::convertMcMchntInfoForDel).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>删除商户列表，size<{}>", globalInstId, globalMcNo, delOrgsMchntInfoList.size());
            deleteMcMchntInfoList(dbsUtil, delOrgsMchntInfoList);
            List<TMPlatBizTmp> delOrgsMcMchntList = delOrgsMchntInfoList.stream().map(this::convertMcMchntInfoToTmpForDel).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>删除商户列表临时表，size<{}>", globalInstId, globalMcNo, delOrgsMcMchntList.size());
            deleteMultiMcDetialInfoByBank(dbsUtil, delOrgsMcMchntList);
        }

    }

    /**
     * 获取营销活动商户信息列表(正式表)
     *
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo> 营销活动商户信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/28 18:35
     */
    private List<Object> getAllMcMchntListInfo() throws Exception {
        List<Object> tmMcMchntInfoList = new ArrayList<>();
        PageInfo pageInfo = new PageInfo();
        int i = 0;
        pageInfo.setPageIndex(i);
        pageInfo.setPageSize(9999);
        TMMcMchntInfo tmMcMchntInfo = new TMMcMchntInfo();
        tmMcMchntInfo.setInstId(globalInstId);
        tmMcMchntInfo.setMcNo(globalMcNo);
        McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
        PageResult tmMcMchntInfoPageInfo = mcMchntInfoMapper.selectMcMchntInfoList(tmMcMchntInfo, pageInfo);
        if (null != tmMcMchntInfoPageInfo && null != tmMcMchntInfoPageInfo.getResult()) {
            tmMcMchntInfoList.addAll(tmMcMchntInfoPageInfo.getResult());
        }
        while (null != tmMcMchntInfoPageInfo && null != tmMcMchntInfoPageInfo.getResult() && tmMcMchntInfoPageInfo.getResult().size() >= 1) {
            i++;
            pageInfo.setPageIndex(i);
            tmMcMchntInfoPageInfo = mcMchntInfoMapper.selectMcMchntInfoList(tmMcMchntInfo, pageInfo);
            if (null != tmMcMchntInfoPageInfo && null != tmMcMchntInfoPageInfo.getResult()) {
                tmMcMchntInfoList.addAll(tmMcMchntInfoPageInfo.getResult());
            }
        }
        return tmMcMchntInfoList;
    }

    /**
     * 营销活动商户信息数据库实体类和接口实体类数据转换
     *
     * @param object 营销活动商户信息表
     * @return cc.rengu.igas.momp.facade.bean.McMchntInfoBean 营销活动商户信息对象
     * @author Jinan Liu
     * @date 2020/4/1 10:33
     */
    private McMchntInfoBean convertMcMchntInfo(Object object) {
        McMchntInfoBean mcMchntInfoBean = new McMchntInfoBean();
        TMMcMchntInfo mcMchntInfo = (TMMcMchntInfo) object;
        try {
            /* 商户范围类型 */
            mcMchntInfoBean.setMchntType(mcMchntInfo.getMchntType());
            /* 商户范围号 */
            mcMchntInfoBean.setMchntNo(mcMchntInfo.getMchntNo());
            /* 商户范围名称 */
            mcMchntInfoBean.setMchntName(mcMchntInfo.getMchntName());
            /* 新增商户标志 */
            mcMchntInfoBean.setNewMchntFlag(mcMchntInfo.getNewMchntFlag());
            /* 退出标志 */
            mcMchntInfoBean.setExitFlag(mcMchntInfo.getExitFlag());
            /* 操作类型 */
            if ((mcMchntInfo.getNewMchntFlag().equals(CommonConstant.MCHNT_REFUSE_FLAG) || mcMchntInfo.getNewMchntFlag().equals(CommonConstant.MCHNT_NEW_FLAG)) && mcMchntInfo.getExitFlag().equals(CommonConstant.MC_EXIT_FLAG)) {
                mcMchntInfoBean.setOprType(CommonConstant.BIZ_OPR_INSERT);
            } else {
                mcMchntInfoBean.setOprType(CommonConstant.EMPTY_STRING);
            }
        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", e.getMessage());
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
        return mcMchntInfoBean;
    }

    /**
     * 营销活动商户信息数据库实体类和接口实体类数据转换
     *
     * @param mchntNo 商户号
     * @return cc.rengu.igas.momp.common.entity.TMMcMchntInfo 营销活动商户信息表
     * @author liujinan
     * @since 2021/6/24 11:10
     */
    private TMMcMchntInfo convertMcMchntInfoForDel(String mchntNo) {
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        try {
            /* 法人机构号 */
            mcMchntInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcMchntInfo.setMcNo(globalMcNo);
            /* 商户范围类型 */
            mcMchntInfo.setMchntType(CommonConstant.ZERO_COMMON_CONSTANT);
            /* 商户范围号 */
            mcMchntInfo.setMchntNo(mchntNo);
        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
        return mcMchntInfo;
    }

    private TMPlatBizTmp convertMcMchntInfoToTmpForDel(TMMcMchntInfo tmMcMchntInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcMchntInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcMchntInfo.getMcNo());
            /* 商户编号 */
            tmPlatBizTmp.setMchntNo(tmMcMchntInfo.getMchntNo());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameCode());

            return tmPlatBizTmp;
        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }
}
